parent
065baa61e5
commit
5dc2d69142
@ -0,0 +1,13 @@ |
|||||||
|
from django.contrib.auth.models import User |
||||||
|
from rest_framework import serializers |
||||||
|
from .models import Club |
||||||
|
|
||||||
|
class UserSerializer(serializers.HyperlinkedModelSerializer): |
||||||
|
class Meta: |
||||||
|
model = User |
||||||
|
fields = ['url', 'username', 'email'] |
||||||
|
|
||||||
|
class ClubSerializer(serializers.HyperlinkedModelSerializer): |
||||||
|
class Meta: |
||||||
|
model = Club |
||||||
|
fields = ['id', 'name'] |
||||||
@ -1,6 +1,26 @@ |
|||||||
from django.shortcuts import render |
from django.shortcuts import render |
||||||
from django.http import HttpResponse |
from django.http import HttpResponse |
||||||
|
from rest_framework import viewsets, permissions |
||||||
|
from django.contrib.auth.models import User |
||||||
|
from .serializers import UserSerializer, ClubSerializer |
||||||
|
from .models import Club |
||||||
|
|
||||||
def index(request): |
def index(request): |
||||||
return HttpResponse("Hello, world. You're at the tournaments index.") |
return HttpResponse("Hello, world. You're at the tournaments index.") |
||||||
|
|
||||||
|
|
||||||
|
class UserViewSet(viewsets.ModelViewSet): |
||||||
|
""" |
||||||
|
API endpoint that allows users to be viewed or edited. |
||||||
|
""" |
||||||
|
queryset = User.objects.all().order_by('-date_joined') |
||||||
|
serializer_class = UserSerializer |
||||||
|
permission_classes = [permissions.IsAuthenticated] |
||||||
|
|
||||||
|
class ClubViewSet(viewsets.ModelViewSet): |
||||||
|
""" |
||||||
|
API endpoint that allows clubs to be viewed or edited. |
||||||
|
""" |
||||||
|
queryset = Club.objects.all().order_by('id') |
||||||
|
serializer_class = ClubSerializer |
||||||
|
permission_classes = [permissions.IsAuthenticated] |
||||||
|
|||||||
Loading…
Reference in new issue