Reputation: 1441
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.
Upvotes: 4
Views: 911
Reputation: 33901
You can get the request inside a serializer method using:
request = self.context['request']
You can then do any conditional validation using 'request.method'
Upvotes: 6