When using regular Django forms, there is this common pattern where we save the form with commit=False and then pass
some extra data to the instance before saving it to the database, like this:
This is very useful because we can save the required information using only one database query and it also make it
possible to handle not nullable columns that was not defined in the form.
To simulate this pattern using a Django REST Framework serializer you can do something like this:
You can also pass several parameters at once:
Example Using APIView
In this example I created an app named core.
models.py
serializers.py
views.py
Example Using ViewSet
Very similar example, using the same models.py and serializers.py as in the previous example.