Looking at it, I would say that this is by design. You shouldn’t use an empty 
label on a multiple choice field. Perhaps this should be clarified in the docs.
Saying that, if you really want an empty label on a multiple choice field, you 
could create your own class that initializes empty_label however you want it.

From: 'Odile Lambert' via Django users [mailto:django-users@googlegroups.com]
Sent: Wednesday, March 13, 2019 1:57 PM
To: Django users
Subject: Bug in Django 2.1 on ModelMultipleChoiceField


Hello,

I believe Bugs in Django are to be reported in this user list. Below is a 
report for a bug which does not seem to be already filed.

In the documentation reference on the ModelMultipleChoiceField there is no 
restrictios mentioned on the empty_label attribute.

Whenever you declare an attribute empy_label for a ModelMultipleChoiceField, it 
generates an error during the system_checks

 typeError " __init__() got multiple values for keyword argument 'empty_label

To reproduce the bug : :

class MyForm(forms.Form):
    field = forms.ModelMultipleChoiceField(
        queryset = Imodelclass.objects.all(),)
        empty_label=('------------'))

Another user on stackoverflow encountered  this same problem see here : 
https://stackoverflow.com/questions/52263426/django-empty-label-for-modelmultiplechoicefield-multiple-values-for-keyword-arg

The cause of the error is the following :

the code ( see fdjango/forms/models.py line 1266 sets the empty_label attribute 
to None while calling the super_class (ModelChoiceField):

super().__init__(queryset, empty_label=None, **kwargs)

while the super_class.__init__ sets the empy_label to "---------".

removing the empty_label= None in the call to the super_class solved the 
problem for me.

best regards

Odile Lambert

--
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<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to 
django-users@googlegroups.com<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/063841b4-5b58-4931-6ea3-29188ccc8171%40laposte.net<https://groups.google.com/d/msgid/django-users/063841b4-5b58-4931-6ea3-29188ccc8171%40laposte.net?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.

-- 
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 https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/c6be6380098a49b6bab737a85e1b5d5b%40iss2.ISS.LOCAL.
For more options, visit https://groups.google.com/d/optout.

Reply via email to