Narendra Kamma
Narendra Kamma

Reputation: 1441

django-rest-framework object-level conditional validation

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

Answers (1)

Tom Christie
Tom Christie

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

Related Questions