#Inherited Serializers Validation

4 messages · Page 1 of 1 (latest)

sacred quiver
#

Hello there i need help with django rest framework
I am implementing a serializer which is inherited from another serializer ... but when validation is executed it execute the validate in parent serializer first the validate in child serializer .... my question is : is there a way to just validate the child serializer first ?

barren mauve
#

You could override the validation logic by redefining the functions on the subclass and not call super().

sacred quiver
#

even if ... i have in serializer A field called user_id and serializer b field called image_id and my class is

    def validate_user_id(self, user_id):
      --- validation A ---

and serializer B

      def validate_image_id(self, image_id):
        --- validation B ---

when i use serializer A it validate serializer B first without even calling super()

barren mauve
#

Hmm. Maybe. You'd have to do some weird stuff. You may be better creating a separate serializer to avoid this problem entirely.