本文整理匯總了Python中django.forms.widgets.NumberInput方法的典型用法代碼示例。如果您正苦於以下問題:Python widgets.NumberInput方法的具體用法?Python widgets.NumberInput怎麽用?Python widgets.NumberInput使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類django.forms.widgets
的用法示例。
在下文中一共展示了widgets.NumberInput方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import NumberInput [as 別名]
def __init__(self, attrs=None, choices=(), default_unit=None):
"""
Split the field in 2 widgets:
- the first widget is a positive integer input,
- the second widget is a select box to choose a pre-defined time unit (minutes, hours,
days, weeks or months),
e.g: 3 hours is split in: 3 (integer input) | hour (select)
"""
self.default_unit = default_unit
super().__init__(
(
widgets.NumberInput({**(attrs or {}), "min": 0}),
widgets.Select(attrs, choices),
)
)
示例2: __init__
# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import NumberInput [as 別名]
def __init__(
self,
attrs=None,
choices=(),
default_effort_unit=None,
default_reference_unit=None,
):
"""
Split the field in 3 widgets:
- the first widget is a positive integer input,
- the second widget is a select box to choose a pre-defined time unit (minutes, hours,
days, weeks or months),
- the third widget is a select box to choose the pre-defined time unit of reference.
e.g: 3 hours/day is split in: 3 (integer input) | hour (select) | day (select)
"""
self.default_effort_unit = default_effort_unit
self.default_reference_unit = default_reference_unit
super().__init__(
(
widgets.NumberInput({**(attrs or {}), "min": 0}),
# Remove the last choice: it can never be chosen as it must be strictly smaller
# than the reference time unit
widgets.Select(attrs, choices[:-1]),
# Remove the first choice: it can never be chosen as it must be strictly greater
# than the effort time unit
widgets.Select(attrs, choices[1:]),
)
)
示例3: test_attrs_not_localized
# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import NumberInput [as 別名]
def test_attrs_not_localized(self):
widget = NumberInput(attrs={'max': 12345, 'min': 1234, 'step': 9999})
self.check_html(
widget, 'name', 'value',
'<input type="number" name="name" value="value" max="12345" min="1234" step="9999">'
)
示例4: __init__
# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import NumberInput [as 別名]
def __init__(self, attrs=None):
# create choices for days, months, years
_attrs = attrs or {} # default class
_attrs['class'] = (_attrs.get('class', '') + ' w-month-year').strip()
_widgets = [widgets.Select(attrs=_attrs, choices=MONTHS.items())]
_attrs['class'] += " w-year"
_widgets.append(widgets.NumberInput(attrs=_attrs))
super(MonthSelectorWidget, self).__init__(_widgets, attrs)
示例5: __init__
# 需要導入模塊: from django.forms import widgets [as 別名]
# 或者: from django.forms.widgets import NumberInput [as 別名]
def __init__(self, **kwargs):
super().__init__(**kwargs)
# No fancy widgets
self.filters.get('court__jurisdiction').field.widget = TextInput()
self.filters.get('court__level_of_appeal').field.widget = TextInput()
self.filters.get('has_reference_to_law').field.widget = NumberInput()