Here are the examples of the python api django.forms.widgets. taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2 Examples
3
View Complete Implementation : duration.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
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),
)
)
0
View Complete Implementation : effort.py
Copyright MIT License
Author : openfun
Copyright MIT License
Author : openfun
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:]),
)
)