Задать вопрос

Тел: +7 965 3737 888

431

Просмотров

2

Ответов

SplitSelectDateTimeWidget

<p>This class extends MultiWidget to create a widget that consists of HTML select elements for Django's forms.DateTimeFields.  This results in a select elements with options for month, day, year, hour, minute, second, and (if using the twelve_hr option) meridiem.</p>
# Default usage of SplitSelectDateTimeWidget
class TimeForm(Form):
    dt = DateTimeField(widget=SplitSelectDateTimeWidget())

<p>Another example hooks into the flexibility of the underlying Select Widgets:</p>
class TimeForm(Form)
    dt = DateTimeField(widget=SplitSelectDateTimeWidget(hour_step=2, \
    minute_step=15, second_step=30, twelve_hr=True, years=[2008,2009,2010]))

<p>The above example displays hours in increments of 2, minutes in increments of 15, and seconds in increments of 30.  Likewise, only the years 2008, 2009,and 2010 are displayed in the years' options.</p>

Вопрос полезен? Да0/Нет0
file_4065.py(1.2Кб)
None

Ответы (2):

Ответbradmontgomery:21.05.2010
Ответ полезен? Да0/Нет0

Thanks for the feedback. I've updated the snippet removing the \'s and cleaned up the docstrings a bit.

Ответramalho:06.05.2010
Ответ полезен? Да0/Нет0

Thanks for sharing a great snippet, Brad. BTW, in Python you almost never need to use backslashes to signal statement continuation. That is because within pairwise delimiters (){}[] and triple-quotes, Python does not consider the line ending a statement terminator. In particular, all of the \'s in your code above may be removed.