当前位置: 首页>>代码示例>>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;未经允许,请勿转载。