Django CheckboxSelectMultiple小部件将---------值添加到查询集 [英] Django CheckboxSelectMultiple widget adds --------- value to query set
问题描述
我有这样的字段的形式:
I have form with such field:
categories = forms.ModelChoiceField(
queryset=Field.objects.all(),
widget=CheckboxSelectMultiple,
required=False
)
在渲染之后,我得到如下所示的第一个值:
And after rendering I get my first value as shown:
<ul>
<li>
<label for="id_categories_0"><input type="checkbox" name="categories" id="id_categories_0">---------</label>
</li>
...
是的,我没有Field Model---- - 。
是否尝试设置可能的空值? (在选择框中使用相同的'-------'在django管理层中显示空值)。
Yes, I don't have Field Model "------". Is it trying to set possible empty value? (same '-------' are used in select boxes to show empty value in the django admin layer).
确定更改----- -----所有字段将会很有用(因为我将需要这样的选项),但是我应该如何实现这一点,什么原因导致这个奇怪的行为?
Sure changing "----------" to "All fields" would be useful (since i will need such option), but how should i achieve that and what causes this weird behavior?
推荐答案
您的问题都在文档中回答: https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ModelChoiceField
both your questions are answered in the documentation: https://docs.djangoproject.com/en/dev/ref/forms/fields/#django.forms.ModelChoiceField
这篇关于Django CheckboxSelectMultiple小部件将---------值添加到查询集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!