本文整理匯總了Python中django.forms.FloatField方法的典型用法代碼示例。如果您正苦於以下問題:Python forms.FloatField方法的具體用法?Python forms.FloatField怎麽用?Python forms.FloatField使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms
的用法示例。
在下文中一共展示了forms.FloatField方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_entry_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [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
示例2: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def formfield(self, **kwargs):
defaults = {'widget': django_forms.TextInput(attrs={'class': 'vIntegerField'}),
'initial': self.default}
defaults.update(kwargs)
return django_forms.FloatField(**defaults)
# -------------------------------------------------------------------------------
示例3: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [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)
示例4: get_prep_value
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def get_prep_value(self, value):
value = super(FloatField, self).get_prep_value(value)
if value is None:
return None
return float(value)
示例5: get_internal_type
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def get_internal_type(self):
return "FloatField"
示例6: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def formfield(self, **kwargs):
defaults = {'form_class': forms.FloatField}
defaults.update(kwargs)
return super(FloatField, self).formfield(**defaults)
示例7: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def __init__(self, project, *args, **kwargs):
kwargs.setdefault('label_suffix', '')
super(SiteBulkEditForm, self).__init__(*args, **kwargs)
self.fields['sites'] = forms.ModelMultipleChoiceField(
widget=forms.CheckboxSelectMultiple,
queryset=project.sites.all(),
)
for attr in project.site_meta_attributes:
q_type = attr['question_type']
q_name = attr['question_name']
if q_type == 'Number':
field = forms.FloatField()
elif q_type == 'Date':
field = forms.DateField()
elif q_type == 'MCQ':
options = attr.get('mcq_options') or []
choices = [o.get('option_text') for o in options]
choices = [(c, c) for c in choices]
field = forms.ChoiceField(choices=choices)
else:
field = forms.CharField()
self.fields[q_name] = field
示例8: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def __init__(self, *args, **kwargs):
name = kwargs.pop('name')
super().__init__(*args, **kwargs)
self.fields[name] = forms.FloatField(label='', required=False,
widget=forms.NumberInput(attrs={'placeholder': _('Value')}))
示例9: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def formfield(self, **kwargs):
defaults = {'form_class': forms.FloatField}
defaults.update(kwargs)
return super().formfield(**defaults)
示例10: extra_field_to_form_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def extra_field_to_form_field(field_type):
if field_type == 'number':
return forms.FloatField(required=False)
elif field_type == 'boolean':
return forms.BooleanField(required=False)
elif field_type == 'datetime':
return forms.DateTimeField(required=False)
elif field_type == 'string':
return forms.CharField(required=False, widget=forms.Textarea)
else:
raise ValueError(
'Invalid field type {}. Field type must be one of: number, boolean, datetime string'.format(field_type)
)
示例11: formfield
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def formfield(self, **kwargs):
return super().formfield(**{
'form_class': forms.FloatField,
**kwargs,
})
示例12: __init__
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def __init__(self, required=True, max_value=None, min_value=None, validators=(), *args,
**kwargs):
self.field = forms.FloatField(
required=required,
max_value=max_value,
min_value=min_value,
validators=validators,
)
super().__init__(*args, **kwargs)
示例13: _create_datatype_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def _create_datatype_field(p_type, p_help, lbl):
"""Create a new field depending on the datatype."""
if p_type == 'integer':
new_field = forms.IntegerField(
label=lbl,
required=False,
help_text=p_help)
elif p_type == 'double':
new_field = forms.FloatField(
label=lbl,
required=False,
help_text=p_help)
elif p_type == 'string':
new_field = forms.CharField(
max_length=STRING_PARAM_MAX_LENGTH,
strip=True,
required=False,
label=lbl,
help_text=p_help)
elif p_type == 'boolean':
new_field = forms.BooleanField(
required=False,
label=lbl,
help_text=p_help)
else: # p_type == 'datetime':
new_field = forms.DateTimeField(
required=False,
label=lbl,
widget=DateTimePickerInput(options=DATE_TIME_WIDGET_OPTIONS),
help_text=p_help)
return new_field
示例14: test_should_float_convert_float
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def test_should_float_convert_float():
assert_conversion(forms.FloatField, Float)
示例15: get_form_field
# 需要導入模塊: from django import forms [as 別名]
# 或者: from django.forms import FloatField [as 別名]
def get_form_field(self, **kwargs):
"""Return a Django form field appropriate for an integer property.
This defaults to a FloatField instance when using Django 0.97 or
later. For 0.96 this defaults to the CharField class.
"""
defaults = {}
if hasattr(forms, 'FloatField'):
defaults['form_class'] = forms.FloatField
defaults.update(kwargs)
return super(FloatProperty, self).get_form_field(**defaults)