Django 2.0.9 - MultiSelectFormField - Parameter to make non-mandatory

0

I want to make the MultiSelectField field not mandatory. When I do not choose any of the options the validation is accusing Required field . I've tried using the parameters blank = True and null = True, but still continue to accuse the field is required.

Does anyone know which parameter should I enter for the MultiSelectField field to be optional and not required?

forms.py

    class MyForm(forms.ModelForm):

        MY_CHOICES = (
            ('1', "A good choice"),
            ('2', "A bad choice"),
        )

        my_field = forms.MultipleChoiceField(
               label='Escolhas', widget=forms.CheckboxSelectMultiple, choices=MY_CHOICE
               )

models.py

from multiselectfield import MultiSelectField

class MyModel(models.Model):
    MY_CHOICES = (
        ('1', "A good choice"),
        ('2', "A bad choice"),
    )
    my_field = MultiSelectField('Escolhas', choices=MY_CHOICES, default=0)
    
asked by anonymous 12.11.2018 / 17:07

1 answer

0

Dude, in documentation does not have any MultiSelectField, so I assume you're using < django-multiselectfield (it would be legal to specify in the question the lib and version).

Viewing code , you can tell that the class extends from models.CharField and uses the comma separated fields below the wads. You can also see that it implements the min_choices and max_choices properties.

I've never used this library, but would try to use blank=True and min_choices=0 .

Ex:

my_field = MultiSelectField('Escolhas', choices=MY_CHOICES, blank=True, min_choices=0)
    
12.11.2018 / 18:48