Hi there,

I don't understand why the form doesn't validate when I don't fill out
a ManyToManyField.

Here's the code:

class Participant(models.Model):
    project = models.ForeignKey(Project, related_name='participants')
    roles = models.ManyToManyField(Role, blank=True, null=True)
    user = models.ForeignKey(User)

class EditParticipantForm(forms.ModelForm):
    roles =
forms.MultipleChoiceField(widget=TableSelectMultiple(item_attrs=('name',)))
    def __init__(self, *args, **kwargs):
        super(EditParticipantForm, self).__init__(*args, **kwargs)
        self.fields['roles'].choices = [(role.pk, role) for role in
Role.objects.all()]
    class Meta:
        model = Participant
        fields = ('roles',)


(The custom widget TableSelectMultiple is taken from there:
http://www.djangosnippets.org/snippets/518/)

If I don't select any option for 'roles' I get the error 'This field
is required'.
Yet, the doc says that the form field shouldn't be required if the
corresponding model field has 'blank=True':
http://www.djangoproject.com/documentation/modelforms/#field-types

Is that a bug or is there a sensible explanation?   :)

Thanks a lot for your help!

Julien
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to