本文整理汇总了Python中django.forms.SelectMultiple方法的典型用法代码示例。如果您正苦于以下问题:Python forms.SelectMultiple方法的具体用法?Python forms.SelectMultiple怎么用?Python forms.SelectMultiple使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.forms
的用法示例。
在下文中一共展示了forms.SelectMultiple方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['document_type'] = forms.MultipleChoiceField(
choices=[(t, t) for t in Document.objects
.order_by().values_list('document_type', flat=True).distinct()],
widget=forms.SelectMultiple(attrs={'class': 'chosen'}),
required=False)
self.fields = OrderedDict((k, self.fields[k]) for k in ['document_type', 'no_detect', 'delete'])
示例2: __init__
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SelectMultiple [as 别名]
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['document_type'] = forms.MultipleChoiceField(
choices=[(t, t) for t in Document.objects
.order_by().values_list('document_type', flat=True).distinct()],
widget=forms.SelectMultiple(attrs={'class': 'chosen'}),
required=False)
self.fields = OrderedDict((k, self.fields[k])
for k in ['document_type', 'no_detect', 'delete'])
示例3: test_default_not_populated_on_selectmultiple
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SelectMultiple [as 别名]
def test_default_not_populated_on_selectmultiple(self):
class PubForm(forms.ModelForm):
mode = forms.CharField(required=False, widget=forms.SelectMultiple)
class Meta:
model = PublicationDefaults
fields = ('mode',)
# Empty data doesn't use the model default because an unselected
# SelectMultiple doesn't have a value in HTML form submission.
mf1 = PubForm({})
self.assertEqual(mf1.errors, {})
m1 = mf1.save(commit=False)
self.assertEqual(m1.mode, '')
self.assertEqual(m1._meta.get_field('mode').get_default(), 'di')
示例4: test_optgroup_select_multiple
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SelectMultiple [as 别名]
def test_optgroup_select_multiple(self):
widget = SelectMultiple(choices=(
('outer1', 'Outer 1'),
('Group "1"', (('inner1', 'Inner 1'), ('inner2', 'Inner 2'))),
))
self.check_html(widget, 'nestchoice', ['outer1', 'inner2'], html=(
"""<select multiple name="nestchoice">
<option value="outer1" selected>Outer 1</option>
<optgroup label="Group "1"">
<option value="inner1">Inner 1</option>
<option value="inner2" selected>Inner 2</option>
</optgroup>
</select>"""
))
示例5: test_many_to_many
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SelectMultiple [as 别名]
def test_many_to_many(self):
self.assertFormfield(Band, 'members', forms.SelectMultiple)
示例6: test_select_multiple_widget_cant_change_delete_related
# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import SelectMultiple [as 别名]
def test_select_multiple_widget_cant_change_delete_related(self):
rel = Individual._meta.get_field('parent').remote_field
widget = forms.SelectMultiple()
wrapper = widgets.RelatedFieldWidgetWrapper(
widget, rel, widget_admin_site,
can_add_related=True,
can_change_related=True,
can_delete_related=True,
)
self.assertTrue(wrapper.can_add_related)
self.assertFalse(wrapper.can_change_related)
self.assertFalse(wrapper.can_delete_related)