Monday, January 28, 2019

Re: validator not working in serializers.ModelSerializer

Many thanks Andreas :-)

On Thursday, January 24, 2019 at 8:40:35 PM UTC+8, Andréas Kühne wrote:
Hi,

Validators are only called when you are updating something on the model - a get request doesn't update anything and the validators will not be called (there is no data sent to the server to validate). The validators will be called on a POST, PUT or PATCH request.

Regards,

Andréas


Den tors 24 jan. 2019 kl 13:19 skrev Maurya Allimuthu <catch...@gmail.com>:
Hi All,

I use  serializers.ModelSerializer and viewset DetailViewset(APIView).

The validators are not getting called on GET request of the viewset via URLS, but the GET request is working.


def validate(self, attrs):
if attrs.get('password') != attrs.get('confirm_password'):
raise serializers.ValidationError("Those passwords don't match.")
return attrs
OR

class Meta:
model = *********
fields = ('***', )
validators = [
trigger_validator
]

Thanks,
Maurya

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ef2204c4-eed2-411c-a157-d8e1d1d63744%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3eec578e-a6e9-4e1e-8d0c-3f77edf956dc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment