1👍
The post_save
method on views exists exactly for this reason. The Django REST Framework documentation doesn’t cover it well, but it is a hook that is called with two arguments, obj
(the object that was saved) and created
(True for POST/PUT-as-create, False for PUT-as-update/PATCH).
You can get access to the sent data with self.request.DATA
, which should allow you to modify saved objects to suit your needs.
1👍
post_save
as mentioned before is now (>2.x) outdated (https://www.django-rest-framework.org/api-guide/generic-views/). The new functions to hook on generic views are:
perform_create(self, serializer)
perform_update(self, serializer)
perform_destroy(self, instance)
- [Answered ]-Django-Fluent-Comments – NoReverseMatch at /rohit/post/new/
- [Answered ]-Django, model instance attribute which is not a field?
Source:stackexchange.com