當前位置: 首頁>>代碼示例>>Python>>正文


Python forms.SelectMultiple方法代碼示例

本文整理匯總了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']) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:10,代碼來源:forms.py

示例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']) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:11,代碼來源:forms.py

示例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') 
開發者ID:nesdis,項目名稱:djongo,代碼行數:17,代碼來源:tests.py

示例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 &quot;1&quot;">
            <option value="inner1">Inner 1</option>
            <option value="inner2" selected>Inner 2</option>
            </optgroup>
            </select>"""
        )) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:16,代碼來源:test_selectmultiple.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:4,代碼來源:tests.py

示例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) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:14,代碼來源:tests.py


注:本文中的django.forms.SelectMultiple方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。