drf_shortcuts.views

views module of DRF (Django REST Framework) shortcuts package.

Functions:

  • append_pagination_info_to_docstring: Class decorator for viewsets which adds documentation on pagination.

  • append_search_info_to_docstring: Class decorator for viewsets which adds documentation on search filtering.

  • append_ordering_info_to_docstring: Class decorator factory which creates viewset decorator adding documentation on ordering of viewset results.

  • append_search_ordering_and_pagination_info_to_docstring: Class decorator factory which creates viewset decorator combining other documenting decorators.

  • get_fields_suitable_for_ordering: Gets field names of a model specified which are suitable for ordering viewset results.

  • get_fields_suitable_for_search: Gets field names of a model specified which are suitable for search viewset results.

  • create_standard_viewset_class: Creates viewset class for the Django model specified.

append_pagination_info_to_docstring

append_pagination_info_to_docstring(cls)

Class decorator for viewsets which adds documentation on pagination.

Documentation is displayed either via Browseable API or upon receiving OPTIONS request.

append_search_info_to_docstring

append_search_info_to_docstring(cls)

Class decorator for viewsets which adds documentation on search filtering.

Documentation is displayed either via Browseable API or upon receiving OPTIONS request.

append_ordering_info_to_docstring

append_ordering_info_to_docstring(fields)

Class decorator factory which creates viewset decorator adding documentation on ordering of viewset results.

Documentation is displayed either via Browseable API or upon receiving OPTIONS request.

Parameters:

  • fields list: The list of field names which are available for ordering.

append_search_ordering_and_pagination_info_to_docstring

append_search_ordering_and_pagination_info_to_docstring(fields)

Class decorator factory which creates viewset decorator combining other documenting decorators.

It's a shortcut for using the following decorators at once:

  • append_pagination_info_to_docstring
  • append_ordering_info_to_docstring
  • append_search_info_to_docstring

Documentation is displayed either via Browseable API or upon receiving OPTIONS request.

Parameters:

  • fields list: The list of field names which are available for ordering.

get_fields_suitable_for_ordering

get_fields_suitable_for_ordering(model)

Gets field names of a model specified which are suitable for ordering viewset results.

Parameters:

  • model django.db.models.base.ModelBase The model class to look up fields of.

Returns: the list of field names suitable for ordering.

get_fields_suitable_for_search(model)

Gets field names of a model specified which are suitable for search viewset results.

Parameters:

  • model django.db.models.base.ModelBase: The model class to look up fields of.

Returns: the list of field names suitable for search.

create_standard_viewset_class

create_standard_viewset_class(model_cls, serializer_cls=None)

Creates viewset class for the Django model specified.

Created viewset will either use serializer specified or a standard one, will have search & ordering fields specified, viewset's queryset will return all model objects ordered by PK and all documentation decorators will be applied to the viewset.

Parameters:

  • model_cls django.db.models.base.ModelBase: The Model class viewset should expose.
  • serializer_cls type: The serializer class viewset should use (optional).

    If omitted the 'standard' serializer class will be used.

    See also drf_shortcuts.serializers.create_standard_serializer_class.

Returns: the standardized viewset class for the model specified.

See also:

  • get_fields_suitable_for_ordering
  • get_fields_suitable_for_search