problem
There are two tables, a product table, a table for the classification of goods stored in the table category_id classification table id, but did not declare the primary key.
When doing the front differential update, incoming merchandise category name, you need to find the back end id classification by product type name, an update is ,, therefore need to find a method to call when receiving a patch request django
Resolution process
Find a patch point into the parent class method
to find the patch methods, discovered a method called partial_update its parent class, continue to point into view
found that the final call or update method, just passed a boolean value of whether the patch. Into the update method
here before incoming request.data, the data can be modified, added category_id can, so we can rewrite the update method.
method one
In this case can be resolved.
Method Two
Last article , referred to in order to make the picture return address does not contain the domain name I rewrote get_serializer_context () method, and now rewrite the update method, update method can be found
get_serializer () method, the points go
we can directly remove kwargs modify data, solve, then the assignment commented context, you can kill two birds with one stone. It should be noted here that the dictionary does not need to directly modify the copy () then modify the
perfect solution, you can modify the incoming class name