But how to add rest_framework.generics to the router views?
No. ViewSets adds a couple of compatibility levels to rest_framework.generics for working with routers.
Should I set up a custom router ( http://www.django-rest-framework.org/api-guide/routers/#custom-routers )? What is the best practice?
If you want to use a view without views, you wonβt write a regular Django URL.
I feel that the real question is completely different, and there will be something like: "How to limit viewing to only certain actions."
In this case, the ModelViewSet gives the answer:
class ViewSet(ViewSetMixin, views.APIView): """ The base ViewSet class does not provide any actions by default. """ pass class GenericViewSet(ViewSetMixin, generics.GenericAPIView): """ The GenericViewSet class does not provide any actions by default, but does include the base set of generic view behavior, such as the `get_object` and `get_queryset` methods. """ pass class ModelViewSet(mixins.CreateModelMixin, mixins.RetrieveModelMixin, mixins.UpdateModelMixin, mixins.DestroyModelMixin, mixins.ListModelMixin, GenericViewSet): """ A viewset that provides default `create()`, `retrieve()`, `update()`, `partial_update()`, `destroy()` and `list()` actions. """ pass
As you can see, you can specialize ModelViewSet by selecting the necessary mixes and inheriting from GenericViewSet .
source share