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 [email protected].
To post to this group, send email to [email protected].
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/6c99c5cc-a163-4731-8b0d-00fa6beda989%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to