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


Python forms.MultipleChoiceField方法代碼示例

本文整理匯總了Python中django.forms.MultipleChoiceField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.MultipleChoiceField方法的具體用法?Python forms.MultipleChoiceField怎麽用?Python forms.MultipleChoiceField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.forms的用法示例。


在下文中一共展示了forms.MultipleChoiceField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['emri'].widget.attrs.update({'class': 'form-control'})

            

# class LendetForm(forms.ModelForm):

#     class Meta:
#         model = ProvimetMundshme
#         fields = '__all__'

#     def __init__(self, *args, **kwargs):
#         super().__init__(*args, **kwargs)
#         self.fields['program'].widget.attrs.update({'class': 'form-control', 'data-type': 'program-listener'})
#         self.fields['semester'].widget.attrs.update({'class': 'form-control'})
#         self.fields['year'].widget.attrs.update({'class': 'form-control'})
#         self.fields['level'].widget.attrs.update({'class': 'form-control'})

#     course = forms.MultipleChoiceField(
#         widget=forms.CheckboxSelectMultiple,
#         choices=[(c.pk, c.name) for c in Course.objects.all()],
#     ) 
開發者ID:urankajtazaj,項目名稱:SEMS,代碼行數:25,代碼來源:forms.py

示例2: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def __init__(self, extension, *args, **kwargs):
        self.extension = extension
        kwargs.setdefault('label', extension.name)
        ext = profile.extensions.get(self.extension.key)
        if ext:
            ext = ext.serialize()
            kwargs.setdefault('initial', [ext['value'], ext['critical']])

        fields = (
            forms.MultipleChoiceField(required=False, choices=extension.CHOICES),
            forms.BooleanField(required=False),
        )

        widget = MultiValueExtensionWidget(choices=extension.CHOICES)
        super(MultiValueExtensionField, self).__init__(
            fields=fields, require_all_fields=False, widget=widget,
            *args, **kwargs) 
開發者ID:mathiasertl,項目名稱:django-ca,代碼行數:19,代碼來源:fields.py

示例3: model_fields_form_factory

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def model_fields_form_factory(model):
    ''' Creates a form for specifying fields from a model to display. '''

    fields = model._meta.get_fields()

    choices = []
    for field in fields:
        if hasattr(field, "verbose_name"):
            choices.append((field.name, field.verbose_name))

    class ModelFieldsForm(forms.Form):
        fields = forms.MultipleChoiceField(
            choices=choices,
            required=False,
        )

    return ModelFieldsForm 
開發者ID:chrisjrn,項目名稱:registrasion,代碼行數:19,代碼來源:forms.py

示例4: test_multiplechoicefield_1

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def test_multiplechoicefield_1(self):
        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')])
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean('')
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean(None)
        self.assertEqual(['1'], f.clean([1]))
        self.assertEqual(['1'], f.clean(['1']))
        self.assertEqual(['1', '2'], f.clean(['1', '2']))
        self.assertEqual(['1', '2'], f.clean([1, '2']))
        self.assertEqual(['1', '2'], f.clean((1, '2')))
        with self.assertRaisesMessage(ValidationError, "'Enter a list of values.'"):
            f.clean('hello')
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean([])
        with self.assertRaisesMessage(ValidationError, "'This field is required.'"):
            f.clean(())
        msg = "'Select a valid choice. 3 is not one of the available choices.'"
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean(['3']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:22,代碼來源:test_multiplechoicefield.py

示例5: test_multiplechoicefield_2

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def test_multiplechoicefield_2(self):
        f = MultipleChoiceField(choices=[('1', 'One'), ('2', 'Two')], required=False)
        self.assertEqual([], f.clean(''))
        self.assertEqual([], f.clean(None))
        self.assertEqual(['1'], f.clean([1]))
        self.assertEqual(['1'], f.clean(['1']))
        self.assertEqual(['1', '2'], f.clean(['1', '2']))
        self.assertEqual(['1', '2'], f.clean([1, '2']))
        self.assertEqual(['1', '2'], f.clean((1, '2')))
        with self.assertRaisesMessage(ValidationError, "'Enter a list of values.'"):
            f.clean('hello')
        self.assertEqual([], f.clean([]))
        self.assertEqual([], f.clean(()))
        msg = "'Select a valid choice. 3 is not one of the available choices.'"
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean(['3']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_multiplechoicefield.py

示例6: test_multiplechoicefield_3

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def test_multiplechoicefield_3(self):
        f = MultipleChoiceField(
            choices=[('Numbers', (('1', 'One'), ('2', 'Two'))), ('Letters', (('3', 'A'), ('4', 'B'))), ('5', 'Other')]
        )
        self.assertEqual(['1'], f.clean([1]))
        self.assertEqual(['1'], f.clean(['1']))
        self.assertEqual(['1', '5'], f.clean([1, 5]))
        self.assertEqual(['1', '5'], f.clean([1, '5']))
        self.assertEqual(['1', '5'], f.clean(['1', 5]))
        self.assertEqual(['1', '5'], f.clean(['1', '5']))
        msg = "'Select a valid choice. 6 is not one of the available choices.'"
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean(['6'])
        msg = "'Select a valid choice. 6 is not one of the available choices.'"
        with self.assertRaisesMessage(ValidationError, msg):
            f.clean(['1', '6']) 
開發者ID:nesdis,項目名稱:djongo,代碼行數:18,代碼來源:test_multiplechoicefield.py

示例7: clean

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def clean(self, value):
        """Clean the list of field values.

        Assert that each field value corresponds to an instance of the class
        `self.model_class`.
        """
        if value is None:
            return None
        # `value` is in fact a list of values since this field is a subclass of
        # forms.MultipleChoiceField.
        set_values = set(value)
        filters = {"%s__in" % self.field_name: set_values}

        instances = self.model_class.objects.filter(**filters)
        if len(instances) != len(set_values):
            unknown = set_values.difference(
                {getattr(instance, self.field_name) for instance in instances}
            )
            error = self.text_for_invalid_object.format(
                obj_name=self.model_class.__name__.lower(),
                unknown_names=", ".join(sorted(unknown)),
            )
            raise forms.ValidationError(error)
        return instances 
開發者ID:maas,項目名稱:maas,代碼行數:26,代碼來源:__init__.py

示例8: get_followers_form

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def get_followers_form(field_name, request, issue, data=None, *args, **kwargs):
    class _form(DefaultForm):
        followers_names = forms.MultipleChoiceField(get_users_choise(issue, 'followers'), required=False,
                                                    label='')  # we dont need coerce function here
        # because add user id to m2m field is ok.

    return _form(field_name, request, issue, data, *args, **kwargs) 
開發者ID:znick,項目名稱:anytask,代碼行數:9,代碼來源:forms.py

示例9: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def __init__(self, *args, **kwargs):
        settings = kwargs.pop('settings', None)
        super(GeneratedPluginSettingForm, self).__init__(*args, **kwargs)

        for field in settings:

            object = field['object']
            if field['types'] == 'char':
                self.fields[field['name']] = forms.CharField(widget=forms.TextInput(), required=False)
            elif field['types'] == 'rich-text' or field['types'] == 'text' or field['types'] == 'Text':
                self.fields[field['name']] = forms.CharField(widget=forms.Textarea, required=False)
            elif field['types'] == 'json':
                self.fields[field['name']] = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                                                                       choices=field['choices'],
                                                                       required=False)
            elif field['types'] == 'number':
                self.fields[field['name']] = forms.CharField(widget=forms.TextInput(attrs={'type': 'number'}))
            elif field['types'] == 'select':
                self.fields[field['name']] = forms.CharField(widget=forms.Select(choices=field['choices']))
            elif field['types'] == 'date':
                self.fields[field['name']] = forms.CharField(
                    widget=forms.DateInput(attrs={'class': 'datepicker'}))
            elif field['types'] == 'boolean':
                self.fields[field['name']] = forms.BooleanField(
                    widget=forms.CheckboxInput(attrs={'is_checkbox': True}),
                    required=False)

            self.fields[field['name']].initial = object.processed_value
            self.fields[field['name']].help_text = object.setting.description 
開發者ID:BirkbeckCTP,項目名稱:janeway,代碼行數:31,代碼來源:forms.py

示例10: PermField

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def PermField():
    #perms = ['read', 'add', 'update', 'delete', 'assign_group', 'remove_group']
    #return forms.MultipleChoiceField(choices=[(c,c) for c in perms])
    perms = ['read', 'write', 'admin', 'admin+delete']
    return forms.ChoiceField(choices=[(c,c) for c in perms]) 
開發者ID:jhuapl-boss,項目名稱:boss,代碼行數:7,代碼來源:forms.py

示例11: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.fields['task_queue'] = forms.MultipleChoiceField(
            choices=[(tq.pk, tq.__str__()) for tq in TaskQueue.objects.all()],
            required=True) 
開發者ID:LexPredict,項目名稱:lexpredict-contraxsuite,代碼行數:7,代碼來源:forms.py

示例12: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [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

示例13: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [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

示例14: get_field

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def get_field(self, **kwargs):
        return forms.MultipleChoiceField(**kwargs) 
開發者ID:wagtail,項目名稱:wagtail,代碼行數:4,代碼來源:field_block.py

示例15: __init__

# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import MultipleChoiceField [as 別名]
def __init__(self, poll, user=None, *args, **kwargs):
        super(PollVoteManyForm, self).__init__(*args, **kwargs)
        self.auto_id = 'id_poll_{pk}_%s'.format(pk=poll.pk)  # Uniqueness "<label for=id_poll_pk_..."
        self.user = user
        self.poll = poll
        self.poll_choices = getattr(poll, 'choices', poll.poll_choices.unremoved())
        choices = ((c.pk, mark_safe(c.description)) for c in self.poll_choices)

        if poll.is_multiple_choice:
            self.fields['choices'] = forms.MultipleChoiceField(
                choices=choices,
                widget=forms.CheckboxSelectMultiple,
                label=_("Poll choices")
            )
        else:
            self.fields['choices'] = forms.ChoiceField(
                choices=choices,
                widget=forms.RadioSelect,
                label=_("Poll choices")
            ) 
開發者ID:nitely,項目名稱:Spirit,代碼行數:22,代碼來源:forms.py


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