How to perform object-level conditional validation using django-rest-framework.
If we use validate(self, attrs) in serializer, validation happens for all calls. I should know and apply it to certain http verbs. ex: I want to perform a object-level validation only for PUT.
1 Answer
You can get the request inside a serializer method using:
request = self.context['request']
You can then do any conditional validation using 'request.method'
1 Comment
Narendra Kamma
Thanks for the answer. In general, do you suggest Serializer class is the right place to write business validations?