本文整理匯總了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
示例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)
示例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"
示例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"
示例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"
示例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_
示例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
示例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
示例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)
示例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",
)
示例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
示例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)
示例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
示例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 []
示例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