1

From docs:

ManyToManyField is represented by django.forms.ModelMultipleChoiceField, which is a MultipleChoiceField whose choices are a model QuerySet.

From source:

class ModelMultipleChoiceField(ModelChoiceField):
    """A MultipleChoiceField whose choices are a model QuerySet."""
    widget = SelectMultiple
    hidden_widget = MultipleHiddenInput

Design of the app which I develop required Select widget instead of SelectMultiple.

Model:

class CV(models.Model):
    region = models.ManyToManyField(Region)

Form:

class RegionForm(forms.ModelForm):
    class Meta:
        model = CV
        widgets = {'region': Select(),} 
        fields = ('region',)     

With the code you see above the validation errors are raised in the template.

Is it a bug or my mistake? Do you know the way to fix this problem?

I159
  • 29,741
  • 31
  • 97
  • 132

0 Answers0