The rationale is described in https://code.djangoproject.com/ticket/19671.

On Tuesday, October 13, 2015 at 7:06:16 AM UTC-7, Mike Herring wrote:
>
> Doc here:
>
> https://docs.djangoproject.com/en/1.8/ref/models/fields/#django.db.models.ManyToManyField
>
> ManyToManyField does not support validators.
>
>
> Is there a particular reason that ManyToManyField doesn't support 
> validators? I would like to add a validator to require the user to select 
> at least 3 options, but it seems the field simply doesn't run validators. I 
> attempted to add one in like this:
>
> from django.core.exceptions import ValidationError
>
> def validate_three(value):
>
>     if len(value) < 3:
>
>         raise ValidationError("Must choose three related posts")
>
>
> BlogPost._meta.get_field('related_posts').validators.append(validate_three)
>
> But when it validates the field later, it says that self.validators == []
>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/f4a3970a-d432-4140-a897-3ee9885ab0e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to