|
You are here |
www.django-rest-framework.org | ||
| | | | |
davi.sh
|
|
| | | | | I often want to include related nested objects in my Django REST Framework ModelViewSets for CRUD operations, but don't want those related objects cluttering up the list view. To accomplish this, you can return a serializer from get_serializer_class() that doesn't include the nested relation when the ViewSet action is list. I ended up doing this on a bunch of viewsets, so I factored the logic out into a separate mixin: from typing import Union from rest_framework import viewsets class ListSerializerMixi.... | |
| | | | |
stribny.name
|
|
| | | | | How to combine request and response serializers into one for use in ModelViewSets. | |
| | | | |
www.laceyhenschel.com
|
|
| | | | | Sometimes the endpoints you get when you use a ModelViewSet aren't enough and you need to add extra endpoints for custom functions. To do this, you could use the APIView class and add a custom route to your `urls.py` file, and that would work fine. But if you have a viewset already, and you feel like this new endpoint belongs with the other endpoints in your viewset, you can use DRF's @action decorator to add a custom endpoint. This means you don't have to change your urls.py -- the method you decorate w... | |
| | | | |
vxlabs.com
|
|
| | | The Django REST Framework is awesome, for a whole bunch of reasons, one of them being the browsable HTML version of your API that it automatically generates for you. As a part of this, it extracts any docstrings that you might have defined for the relevant class (ViewSet or CBV) and adds an HTML version of this documentation to the browsable API, like this: However, as described in the relevant documentation, it expects Markdown syntax by default. I like Markdown, but the rest of my Python docstrings are... | ||