Ibolit
Ibolit

Reputation: 9720

Django-rest-framework: Validate a ListSerializer

I receive a number of similar objects as an input for my API, and I deserialize them using my own serializer with the parameter many=True like this:

serializer = MySerializer(data=request.data, many=True)

The serializer is an instance of ListSerializer.

Then I need to make sure that there are certain combinations of objects in that list. However, I don't seem to find a way to write a .validate() method on the ListSerializer of replace it by my own ListSerializer implementation.

Is there a way to do this validation in the serializer, or do I have to iterate over the deserialized objects and check them?

Upvotes: 2

Views: 2006

Answers (1)

Kendas
Kendas

Reputation: 2253

The Django REST frameworks documentation has a section on customizing ListSerializer behavior.

This entails creating a custom subclass of ListSerializer. You would probably want to create some custom validation in your subclass.

Upvotes: 3

Related Questions