当前位置: 首页>>代码示例>>Python>>正文


Python forms.IntegerField方法代码示例

本文整理汇总了Python中django.forms.IntegerField方法的典型用法代码示例。如果您正苦于以下问题:Python forms.IntegerField方法的具体用法?Python forms.IntegerField怎么用?Python forms.IntegerField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.forms的用法示例。


在下文中一共展示了forms.IntegerField方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_modelinstance_form

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def get_modelinstance_form(metadata_class):
    model_class = metadata_class._meta.get_model('modelinstance')

    # Restrict content type choices to the models set in seo_models
    content_types = get_seo_content_types(metadata_class._meta.seo_models)

    # Get a list of fields, with _content_type at the start
    important_fields = ['_content_type'] + ['_object_id'] + core_choice_fields(metadata_class)
    _fields = important_fields + list(fields_for_model(model_class,
                                                  exclude=important_fields).keys())

    class ModelMetadataForm(forms.ModelForm):
        _content_type = forms.ModelChoiceField(
            queryset=ContentType.objects.filter(id__in=content_types),
            empty_label=None,
            label=capfirst(_("model")),
        )

        _object_id = forms.IntegerField(label=capfirst(_("ID")))

        class Meta:
            model = model_class
            fields = _fields

    return ModelMetadataForm 
开发者ID:whyflyru,项目名称:django-seo,代码行数:27,代码来源:admin.py

示例2: get_field_kind

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def get_field_kind(field):
  if field['kind'] == 'string':
    return forms.CharField(max_length=255, required=False)
  elif field['kind'] == 'email':
    return forms.EmailField(max_length=255, required=False)
  elif field['kind'] == 'integer':
    return forms.IntegerField(required=False)
  elif field['kind'] == 'boolean':
    return forms.BooleanField(required=False)
  elif field['kind'] == 'text':
    return forms.CharField(widget=forms.Textarea(), required=False)
  elif field['kind'] == 'choice':
    return forms.ChoiceField(choices=map(lambda c: (c,c), field['choices']))
  elif field['kind'] == 'timezones':
    return TimezoneField()
  elif field['kind'] == 'authentication':
    return SwitchField('user', 'service', required=True)
  elif field['kind'] == 'json':
    return JsonField(required=False)
  elif field['kind'] == 'integer_list':
    return CommaSeparatedIntegerField(required=False)
  elif field['kind'] == 'string_list':
    return CommaSeparatedCharField(required=False)
  else:
    return forms.CharField(max_length=255, required=False) 
开发者ID:google,项目名称:starthinker,代码行数:27,代码来源:forms_json.py

示例3: test_form_mutation_without_context

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def test_form_mutation_without_context():
    class TestForm(Form):
        a = IntegerField()

        def save(self, *args, **kwargs):
            return "hello"

    class TestMutation(FormMutation):
        class Meta:
            form_class = TestForm

    @strawberry.input
    class TestInput:
        a: int

    assert TestMutation.Mutation(None, TestInput(a=1)) == "hello" 
开发者ID:pythonitalia,项目名称:pycon,代码行数:18,代码来源:test_mutations.py

示例4: test_form_mutation_response_can_be_converted_using_transform_method

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def test_form_mutation_response_can_be_converted_using_transform_method():
    class TestForm(Form):
        a = IntegerField()

        def save(self, *args, **kwargs):
            return "hello"

    class TestMutation(FormMutation):
        @classmethod
        def transform(cls, result):
            return "world"

        class Meta:
            form_class = TestForm

    @strawberry.input
    class TestInput:
        a: int

    assert TestMutation.Mutation(None, TestInput(a=1)) == "world" 
开发者ID:pythonitalia,项目名称:pycon,代码行数:22,代码来源:test_mutations.py

示例5: test_form_mutation_transform_is_not_required

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def test_form_mutation_transform_is_not_required():
    class TestForm(Form):
        a = IntegerField()

        def save(self, *args, **kwargs):
            return "hello"

    class TestMutation(FormMutation):
        class Meta:
            form_class = TestForm

    @strawberry.input
    class TestInput:
        a: int

    assert TestMutation.Mutation(None, TestInput(a=1)) == "hello" 
开发者ID:pythonitalia,项目名称:pycon,代码行数:18,代码来源:test_mutations.py

示例6: validators

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        validators_ = super(IntegerField, self).validators
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if min_value is not None:
            for validator in validators_:
                if isinstance(validator, validators.MinValueValidator) and validator.limit_value >= min_value:
                    break
            else:
                validators_.append(validators.MinValueValidator(min_value))
        if max_value is not None:
            for validator in validators_:
                if isinstance(validator, validators.MaxValueValidator) and validator.limit_value <= max_value:
                    break
            else:
                validators_.append(validators.MaxValueValidator(max_value))
        return validators_ 
开发者ID:Yeah-Kun,项目名称:python,代码行数:21,代码来源:__init__.py

示例7: set_fields

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def set_fields(cls, category, products):
        for product in products:
            if product.description:
                help_text = "$%d each -- %s" % (
                    product.price,
                    product.description,
                )
            else:
                help_text = "$%d each" % product.price

            field = forms.IntegerField(
                label=product.name,
                help_text=help_text,
                min_value=0,
                max_value=500,  # Issue #19. We should figure out real limit.
            )
            cls.base_fields[cls.field_name(product)] = field 
开发者ID:chrisjrn,项目名称:registrasion,代码行数:19,代码来源:forms.py

示例8: staff_products_form_factory

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def staff_products_form_factory(user):
    ''' Creates a StaffProductsForm that restricts the available products to
    those that are available to a user. '''

    products = inventory.Product.objects.all()
    products = ProductController.available_products(user, products=products)

    product_ids = [product.id for product in products]
    product_set = inventory.Product.objects.filter(id__in=product_ids)

    class StaffProductsForm(forms.Form):
        ''' Form for allowing staff to add an item to a user's cart. '''

        product = forms.ModelChoiceField(
            widget=forms.Select,
            queryset=product_set,
        )

        quantity = forms.IntegerField(
            min_value=0,
        )

    return StaffProductsForm 
开发者ID:chrisjrn,项目名称:registrasion,代码行数:25,代码来源:forms.py

示例9: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def __init__(self, *args, **kwargs):
        self.event = kwargs.pop('event')

        super(GiftSetForm, self).__init__(*args, **kwargs)

        available_gifts = Gift.objects.filter(event=self.event)
        self.gift_form_ids = {}

        for gift in available_gifts:
            id = "gift_{}".format(gift.pk)
            self.gift_form_ids[gift.pk] = id

            number = 0
            if self.instance:
                number = self.instance.get_gift_num(gift)

            self.fields[id] = forms.IntegerField(label=gift.name,
                                                 required=False,
                                                 min_value=0,
                                                 initial=number) 
开发者ID:helfertool,项目名称:helfertool,代码行数:22,代码来源:set.py

示例10: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def __init__(self, prizes, *args, **kwargs):
        super(DrawPrizeWinnersForm, self).__init__(*args, **kwargs)
        self.choices = []
        for prize in prizes:
            self.choices.append(
                (
                    prize.id,
                    mark_safe(
                        format_html(
                            '<a href="{0}">{1}</a>', viewutil.admin_url(prize), prize
                        )
                    ),
                )
            )
        self.fields['prizes'] = forms.TypedMultipleChoiceField(
            choices=self.choices,
            initial=[prize.id for prize in prizes],
            coerce=lambda x: int(x),
            label='Prizes',
            empty_value='',
            widget=forms.widgets.CheckboxSelectMultiple,
        )
        self.fields['seed'] = forms.IntegerField(
            required=False,
            label='Random Seed',
            help_text="Completely optional, if you don't know what this is, don't worry about it",
        ) 
开发者ID:GamesDoneQuick,项目名称:donation-tracker,代码行数:29,代码来源:forms.py

示例11: get_entry_field

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def get_entry_field(self, questionanswer=None, student=None):
        resp_type = self.question.config.get('resp_type', 'float')
        if questionanswer:
            initial = questionanswer.answer.get('data', '')
        else:
            initial = None

        if resp_type == 'int':
            field = forms.IntegerField(required=False, initial=initial)
        else:
            field = forms.FloatField(required=False, initial=initial)

        field.widget.attrs.update({'class': 'numeric-answer'})
        return field 
开发者ID:sfu-fas,项目名称:coursys,代码行数:16,代码来源:text.py

示例12: __init__

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def __init__(self, *args, **kwargs):
        reg = kwargs.pop('registration')
        super(ApproveRegistrationForm, self).__init__(*args, **kwargs)

        workflow = ApproveRegistrationWorkflow(reg)

        self.fields['send_confirm_email'].initial = workflow.default_send_confirm_email
        self.fields['invite_to_slack'].initial = workflow.default_invite_to_slack

        section_list = reg.season.section_list()
        if len(section_list) > 1:
            section_options = [(season.id, season.section.name) for season in section_list]
            self.fields['section'] = forms.ChoiceField(choices=section_options,
                                                       initial=workflow.default_section.id)

        if workflow.is_late:
            self.fields['retroactive_byes'] = forms.IntegerField(initial=workflow.default_byes)
            self.fields['late_join_points'] = forms.FloatField(initial=workflow.default_ljp) 
开发者ID:cyanfish,项目名称:heltour,代码行数:20,代码来源:forms.py

示例13: check

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def check(self, **kwargs):
        errors = super(IntegerField, self).check(**kwargs)
        errors.extend(self._check_max_length_warning())
        return errors 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:__init__.py

示例14: _check_max_length_warning

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def _check_max_length_warning(self):
        if self.max_length is not None:
            return [
                checks.Warning(
                    "'max_length' is ignored when used with IntegerField",
                    hint="Remove 'max_length' from field",
                    obj=self,
                    id='fields.W122',
                )
            ]
        return [] 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:__init__.py

示例15: validators

# 需要导入模块: from django import forms [as 别名]
# 或者: from django.forms import IntegerField [as 别名]
def validators(self):
        # These validators can't be added at field initialization time since
        # they're based on values retrieved from `connection`.
        range_validators = []
        internal_type = self.get_internal_type()
        min_value, max_value = connection.ops.integer_field_range(internal_type)
        if min_value is not None:
            range_validators.append(validators.MinValueValidator(min_value))
        if max_value is not None:
            range_validators.append(validators.MaxValueValidator(max_value))
        return super(IntegerField, self).validators + range_validators 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:13,代码来源:__init__.py


注:本文中的django.forms.IntegerField方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。