本文整理汇总了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()