Reputation: 423
I am starting using Django REST framework, I found the framework doesn't have the same level of form validation. If I use form validation, I have the endpoint as the form, and serializes the data, which seems it is not a benefit to use the framework. How can I solve this?
Upvotes: 1
Views: 1571
Reputation: 6523
Assuming what you are referring to is object
level validation. (I.e. acting on more than one field together) you need to do this in the serializer (as per serializer docs) this is done by overriding:
def validate(self, data):
On the serializer class.
An example of this (from the included link):
def validate(self, data):
"""
Check that the start is before the stop.
"""
if data['start'] > data['finish']:
raise serializers.ValidationError("finish must occur after start")
return data
Upvotes: 4