Skip to content

Commit

Permalink
Merge pull request #39 from molcay/master
Browse files Browse the repository at this point in the history
Minor fixes
  • Loading branch information
shabda committed Nov 2, 2018
2 parents 0943ac7 + 58c72c0 commit 6cbd292
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/access-control.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ We will add an user serializer, which will allow creating. Add the following cod

.. code-block:: python
# ...
from django.contrib.auth.models import User
# ...
class UserSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
10 changes: 6 additions & 4 deletions docs/more-views-and-viewsets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Lets get back to :code:`ChoiceList`.
path("polls/<int:pk>/choices/", ChoiceList.as_view(), name="choice_list"),
]
# views.py
# apiviews.py
# ...
class ChoiceList(generics.ListCreateAPIView):
Expand All @@ -130,7 +130,7 @@ And for :code:`CreateVote`,
path("polls/<int:pk>/choices/<int:choice_pk>/vote/", CreateVote.as_view(), name="polls_list"),
]
# views.py
# apiviews.py
# ...
class CreateVote(APIView):
Expand Down Expand Up @@ -161,6 +161,8 @@ This is what it will look like:
# urls.py
# ...
from rest_framework.routers import DefaultRouter
from .apiviews import PollViewSet
router = DefaultRouter()
router.register('polls', PollViewSet, base_name='polls')
Expand All @@ -172,7 +174,7 @@ This is what it will look like:
urlpatterns += router.urls
# views.py
# apiviews.py
# ...
from rest_framework import viewsets
Expand Down Expand Up @@ -200,7 +202,7 @@ We have seen 4 ways to build API views until now

So which one should you use when? My rule of thumb is,

- Use :code:`viewsets.ModelViewSet` when you are goin to allow all or most of CRUD operations on a model.
- Use :code:`viewsets.ModelViewSet` when you are going to allow all or most of CRUD operations on a model.
- Use :code:`generics.*` when you only want to allow some operations on a model
- Use :code:`APIView` when you want to completely customize the behaviour.

Expand Down
4 changes: 3 additions & 1 deletion docs/views-and-generic-views.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Using DRF generic views to simplify code

The :code:`PollList` and :code:`PollDetail` get the work done, but there are bunch of common operations, we can do it in abstract away.

The generic views of Django Rest Framework help us in code reusablity. They infer the response format and allowed methods from the serilizer class and base class.
The generic views of Django Rest Framework help us in code reusablity. They infer the response format and allowed methods from the serializer class and base class.

Change your :code:`apiviews.py` to the below code, and leave urls.py as is.

Expand Down Expand Up @@ -205,6 +205,8 @@ Connect the new apiviews to urls.py.
.. code-block:: python
# ...
from .apiviews import ChoiceList, CreateVote, # ...
urlpatterns = [
# ...
path("choices/", ChoiceList.as_view(), name="choice_list"),
Expand Down

0 comments on commit 6cbd292

Please sign in to comment.