mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-28 20:44:03 +03:00
Add permissions to quickstart tutorial (#7113)
This commit is contained in:
parent
5f3f2ef106
commit
62193e0378
|
@ -85,6 +85,7 @@ Right, we'd better write some views then. Open `tutorial/quickstart/views.py` a
|
||||||
|
|
||||||
from django.contrib.auth.models import User, Group
|
from django.contrib.auth.models import User, Group
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
|
from rest_framework import permissions
|
||||||
from tutorial.quickstart.serializers import UserSerializer, GroupSerializer
|
from tutorial.quickstart.serializers import UserSerializer, GroupSerializer
|
||||||
|
|
||||||
|
|
||||||
|
@ -94,6 +95,7 @@ Right, we'd better write some views then. Open `tutorial/quickstart/views.py` a
|
||||||
"""
|
"""
|
||||||
queryset = User.objects.all().order_by('-date_joined')
|
queryset = User.objects.all().order_by('-date_joined')
|
||||||
serializer_class = UserSerializer
|
serializer_class = UserSerializer
|
||||||
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
|
|
||||||
class GroupViewSet(viewsets.ModelViewSet):
|
class GroupViewSet(viewsets.ModelViewSet):
|
||||||
|
@ -102,6 +104,7 @@ Right, we'd better write some views then. Open `tutorial/quickstart/views.py` a
|
||||||
"""
|
"""
|
||||||
queryset = Group.objects.all()
|
queryset = Group.objects.all()
|
||||||
serializer_class = GroupSerializer
|
serializer_class = GroupSerializer
|
||||||
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
Rather than write multiple views we're grouping together all the common behavior into classes called `ViewSets`.
|
Rather than write multiple views we're grouping together all the common behavior into classes called `ViewSets`.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user