With such kind of router we have next resources: That mixin adds automatic filtering by parent lookups: # yourapp.viewsįrom rest_framework_extenions.mixins import NestedViewSetMixinĬlass UserViewSet(NestedViewSetMinxin, ModelViewSet):Ĭlass GroupViewSet(NestedViewSetMixin, ModelViewSet):Ĭlass PermissionViewSet(NestedViewSetMixin, ModelViewSet): They should add mixin NestedViewSetMixin. There is one requirement for viewsets which used in nested routers. Router.register(r'users', UserViewSet, base_name='user') Nested routes allows you create nested resources with viewsets.įrom rest_framework_extensions.routers import ExtendedSimpleRouter For example you can use it with third-party routers: from rest_framework_extensions.routers import ExtendedRouterMixinįrom third_party_app.routers import SomeRouterĬlass ExtendedSomeRouter(ExtendedRouterMixin, SomeRouter): ExtendedRouterMixin has all set of drf-extensions features. That means that you can use the only features you need in your custom routers. Or SimpleRouter with ExtendedSimpleRouter: from rest_framework_extensions.routers import (Įvery feature in extended routers has it's own mixin. You should replace DefaultRouter with ExtendedDefaultRouter: from rest_framework_extensions.routers import ( For example you have standard implementation: from rest_framework.routers import DefaultRouter You will need to use custom ExtendedDefaultRouter or ExtendedSimpleRouter for routing if you want to take advantages of described extensions. Please, read more about caching, key construction and conditional requests. Usage: from rializers import UserSerializerįrom rest_framework_extensions.mixins import CacheResponseAndETAGMixinĬlass UserViewSet(CacheResponseAndETAGMixin, viewsets.ModelView):
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |