本文整理匯總了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)