Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class CustomListSerializer(serializers.ListSerializer):
  2. def __init__(self, *args, **kwargs):
  3. count = kwargs.pop('count', None)
  4. self.count = count
  5. super().__init__(*args, **kwargs)
  6.  
  7. def to_representation(self, data):
  8. if self.count is not None:
  9. if len(data) != self.count:
  10. raise serializers.ValidationError("Incorrect list size")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement