Viewsets

API views mixins

class djangoapp_sample.viewsets.mixins.ConditionalResumedSerializerMixin[source]

Overrides get_serializer_class to use a resumed Serializer in list.

Set resumed_serializer_class attribute on your viewset to enable this behavior else the default serializer from serializer_class is always used.

This won’t work with classes which does not set attribute action like APIView.

The goal of this behavior is to have lighter payload on lists which does not need to return everything from an object.

Blog API views

class djangoapp_sample.viewsets.blog.BlogViewSet(**kwargs)[source]

Viewset for all HTTP methods on Blog model.

model

alias of djangoapp_sample.models.blog.Blog

serializer_class

alias of djangoapp_sample.serializers.blog.BlogSerializer

get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)

Article API views

class djangoapp_sample.viewsets.article.ArticleViewSet(**kwargs)[source]

Viewset for all HTTP methods on Article model.

model

alias of djangoapp_sample.models.article.Article

serializer_class

alias of djangoapp_sample.serializers.article.ArticleSerializer

resumed_serializer_class

alias of djangoapp_sample.serializers.article.ArticleResumeSerializer

get_queryset()[source]

Get the list of items for this view. This must be an iterable, and may be a queryset. Defaults to using self.queryset.

This method should always be used rather than accessing self.queryset directly, as self.queryset gets evaluated only once, and those results are cached for all subsequent requests.

You may want to override this if you need to provide different querysets depending on the incoming request.

(Eg. return a list of items that is specific to the user)