Being new to django rest framework , I often get puzzled as what exactly is the use of viewset when we can overwrite crud methods in serializers too .Another thing is that how is overwriting crud methods in serializers different from overwriting crud methods in viewsets ?
-
viewsets provide the entry point into the API - the GET, PUT, PATCH, DELETE etc methodsIain Shelvington– Iain Shelvington2019-12-29 20:58:07 +00:00Commented Dec 29, 2019 at 20:58
-
Cool . I get that but what is the difference between the overwriting of the crud methods in serializers.py and views.py ?horrible_nerd– horrible_nerd2019-12-29 21:10:40 +00:00Commented Dec 29, 2019 at 21:10
Add a comment
|
1 Answer
Technically, you can overwrite whatever you like wherever you like. The whole thing is just a convention.
The main idea is separation of concerns.
When you overwrite your views it's for the purpose of pre-processing the incoming request.
When you overwrite your serializers - it's because you want to change how the incoming data is serialized to be stored in your system (or how it is deserialized to be shown to the front-end).
1 Comment
horrible_nerd
Can you explain this with an example ? It will make my understanding even better .