Django REST Framework: Generics or ModelViewSets?

后端 未结 3 843
说谎
说谎 2020-12-31 10:53

I use generics and plain urls for my REST API, but now I stuck with problem: I want custom actions, simple views to make some things with my models, like \"run\", \"publish\

3条回答
  •  迷失自我
    2020-12-31 11:14

    The difference is what methods they offer.

    For example:

    GenericViewSet inherits from GenericAPIView but does not provide any implementations of basic actions. Just only get_object, get_queryset.

    ModelViewSet inherits from GenericAPIView and includes implementations for various actions. In other words you dont need implement basic actions as list, retrieve, create, update or destroy. Of course you can override them and implement your own list or your own create methods.

    You can read more about it, in the API REFERENCE section: ModelViewSet

提交回复
热议问题