widgets.txt 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. =======
  2. Widgets
  3. =======
  4. .. module:: django.forms.widgets
  5. :synopsis: Django's built-in form widgets.
  6. .. currentmodule:: django.forms
  7. A widget is Django's representation of a HTML input element. The widget
  8. handles the rendering of the HTML, and the extraction of data from a GET/POST
  9. dictionary that corresponds to the widget.
  10. .. tip::
  11. Widgets should not be confused with the :doc:`form fields </ref/forms/fields>`.
  12. Form fields deal with the logic of input validation and are used directly
  13. in templates. Widgets deal with rendering of HTML form input elements on
  14. the web page and extraction of raw submitted data. However, widgets do
  15. need to be :ref:`assigned <widget-to-field>` to form fields.
  16. .. _widget-to-field:
  17. Specifying widgets
  18. ------------------
  19. Whenever you specify a field on a form, Django will use a default widget
  20. that is appropriate to the type of data that is to be displayed. To find
  21. which widget is used on which field, see the documentation about
  22. :ref:`built-in fields`.
  23. However, if you want to use a different widget for a field, you can
  24. just use the :attr:`~Field.widget` argument on the field definition. For
  25. example::
  26. from django import forms
  27. class CommentForm(forms.Form):
  28. name = forms.CharField()
  29. url = forms.URLField()
  30. comment = forms.CharField(widget=forms.Textarea)
  31. This would specify a form with a comment that uses a larger :class:`Textarea`
  32. widget, rather than the default :class:`TextInput` widget.
  33. Setting arguments for widgets
  34. -----------------------------
  35. Many widgets have optional extra arguments; they can be set when defining the
  36. widget on the field. In the following example, the
  37. :attr:`~django.forms.extras.widgets.SelectDateWidget.years` attribute is set
  38. for a :class:`~django.forms.extras.widgets.SelectDateWidget`::
  39. from django.forms.fields import DateField, ChoiceField, MultipleChoiceField
  40. from django.forms.widgets import RadioSelect, CheckboxSelectMultiple
  41. from django.forms.extras.widgets import SelectDateWidget
  42. BIRTH_YEAR_CHOICES = ('1980', '1981', '1982')
  43. FAVORITE_COLORS_CHOICES = (('blue', 'Blue'),
  44. ('green', 'Green'),
  45. ('black', 'Black'))
  46. class SimpleForm(forms.Form):
  47. birth_year = DateField(widget=SelectDateWidget(years=BIRTH_YEAR_CHOICES))
  48. favorite_colors = forms.MultipleChoiceField(required=False,
  49. widget=CheckboxSelectMultiple, choices=FAVORITE_COLORS_CHOICES)
  50. See the :ref:`built-in widgets` for more information about which widgets
  51. are available and which arguments they accept.
  52. Widgets inheriting from the Select widget
  53. -----------------------------------------
  54. Widgets inheriting from the :class:`Select` widget deal with choices. They
  55. present the user with a list of options to choose from. The different widgets
  56. present this choice differently; the :class:`Select` widget itself uses a
  57. ``<select>`` HTML list representation, while :class:`RadioSelect` uses radio
  58. buttons.
  59. :class:`Select` widgets are used by default on :class:`ChoiceField` fields. The
  60. choices displayed on the widget are inherited from the :class:`ChoiceField` and
  61. changing :attr:`ChoiceField.choices` will update :attr:`Select.choices`. For
  62. example::
  63. >>> from django import forms
  64. >>> CHOICES = (('1', 'First',), ('2', 'Second',))
  65. >>> choice_field = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
  66. >>> choice_field.choices
  67. [('1', 'First'), ('2', 'Second')]
  68. >>> choice_field.widget.choices
  69. [('1', 'First'), ('2', 'Second')]
  70. >>> choice_field.widget.choices = ()
  71. >>> choice_field.choices = (('1', 'First and only',),)
  72. >>> choice_field.widget.choices
  73. [('1', 'First and only')]
  74. Widgets which offer a :attr:`~Select.choices` attribute can however be used
  75. with fields which are not based on choice -- such as a :class:`CharField` --
  76. but it is recommended to use a :class:`ChoiceField`-based field when the
  77. choices are inherent to the model and not just the representational widget.
  78. Customizing widget instances
  79. ----------------------------
  80. When Django renders a widget as HTML, it only renders very minimal markup -
  81. Django doesn't add class names, or any other widget-specific attributes. This
  82. means, for example, that all :class:`TextInput` widgets will appear the same
  83. on your Web pages.
  84. There are two ways to customize widgets: :ref:`per widget instance
  85. <styling-widget-instances>` and :ref:`per widget class <styling-widget-classes>`.
  86. .. _styling-widget-instances:
  87. Styling widget instances
  88. ^^^^^^^^^^^^^^^^^^^^^^^^
  89. If you want to make one widget instance look different from another, you will
  90. need to specify additional attributes at the time when the widget object is
  91. instantiated and assigned to a form field (and perhaps add some rules to your
  92. CSS files).
  93. For example, take the following simple form::
  94. from django import forms
  95. class CommentForm(forms.Form):
  96. name = forms.CharField()
  97. url = forms.URLField()
  98. comment = forms.CharField()
  99. This form will include three default :class:`TextInput` widgets, with default
  100. rendering -- no CSS class, no extra attributes. This means that the input boxes
  101. provided for each widget will be rendered exactly the same::
  102. >>> f = CommentForm(auto_id=False)
  103. >>> f.as_table()
  104. <tr><th>Name:</th><td><input type="text" name="name" /></td></tr>
  105. <tr><th>Url:</th><td><input type="text" name="url"/></td></tr>
  106. <tr><th>Comment:</th><td><input type="text" name="comment" /></td></tr>
  107. On a real Web page, you probably don't want every widget to look the same. You
  108. might want a larger input element for the comment, and you might want the
  109. 'name' widget to have some special CSS class. It is also possible to specify
  110. the 'type' attribute to take advantage of the new HTML5 input types. To do
  111. this, you use the :attr:`Widget.attrs` argument when creating the widget::
  112. class CommentForm(forms.Form):
  113. name = forms.CharField(
  114. widget=forms.TextInput(attrs={'class':'special'}))
  115. url = forms.URLField()
  116. comment = forms.CharField(
  117. widget=forms.TextInput(attrs={'size':'40'}))
  118. Django will then include the extra attributes in the rendered output:
  119. >>> f = CommentForm(auto_id=False)
  120. >>> f.as_table()
  121. <tr><th>Name:</th><td><input type="text" name="name" class="special"/></td></tr>
  122. <tr><th>Url:</th><td><input type="text" name="url"/></td></tr>
  123. <tr><th>Comment:</th><td><input type="text" name="comment" size="40"/></td></tr>
  124. .. _styling-widget-classes:
  125. Styling widget classes
  126. ^^^^^^^^^^^^^^^^^^^^^^
  127. With widgets, it is possible to add media (``css`` and ``javascript``)
  128. and more deeply customize their appearance and behavior.
  129. In a nutshell, you will need to subclass the widget and either
  130. :ref:`define a class "Media" <media-as-a-static-definition>` as a member of the
  131. subclass, or :ref:`create a property "media" <dynamic-property>`, returning an
  132. instance of that class.
  133. These methods involve somewhat advanced Python programming and are described in
  134. detail in the :doc:`Form Media </topics/forms/media>` topic guide.
  135. .. _base-widget-classes:
  136. Base Widget classes
  137. -------------------
  138. Base widget classes :class:`Widget` and :class:`MultiWidget` are subclassed by
  139. all the :ref:`built-in widgets <built-in widgets>` and may serve as a
  140. foundation for custom widgets.
  141. .. class:: Widget(attrs=None)
  142. This abstract class cannot be rendered, but provides the basic attribute
  143. :attr:`~Widget.attrs`. You may also implement or override the
  144. :meth:`~Widget.render()` method on custom widgets.
  145. .. attribute:: Widget.attrs
  146. A dictionary containing HTML attributes to be set on the rendered
  147. widget.
  148. .. code-block:: python
  149. >>> name = forms.TextInput(attrs={'size': 10, 'title': 'Your name',})
  150. >>> name.render('name', 'A name')
  151. u'<input title="Your name" type="text" name="name" value="A name" size="10" />'
  152. .. method:: render(name, value, attrs=None)
  153. Returns HTML for the widget, as a Unicode string. This method must be
  154. implemented by the subclass, otherwise ``NotImplementedError`` will be
  155. raised.
  156. The 'value' given is not guaranteed to be valid input, therefore
  157. subclass implementations should program defensively.
  158. .. method:: value_from_datadict(self, data, files, name)
  159. Given a dictionary of data and this widget's name, returns the value
  160. of this widget. Returns ``None`` if a value wasn't provided.
  161. .. class:: MultiWidget(widgets, attrs=None)
  162. A widget that is composed of multiple widgets.
  163. :class:`~django.forms.MultiWidget` works hand in hand with the
  164. :class:`~django.forms.MultiValueField`.
  165. :class:`MultiWidget` has one required argument:
  166. .. attribute:: MultiWidget.widgets
  167. An iterable containing the widgets needed.
  168. And one required method:
  169. .. method:: decompress(value)
  170. This method takes a single "compressed" value from the field and
  171. returns a list of "decompressed" values. The input value can be
  172. assumed valid, but not necessarily non-empty.
  173. This method **must be implemented** by the subclass, and since the
  174. value may be empty, the implementation must be defensive.
  175. The rationale behind "decompression" is that it is necessary to "split"
  176. the combined value of the form field into the values for each widget.
  177. An example of this is how :class:`SplitDateTimeWidget` turns a
  178. :class:`~datetime.datetime` value into a list with date and time split
  179. into two separate values::
  180. class SplitDateTimeWidget(MultiWidget):
  181. # ...
  182. def decompress(self, value):
  183. if value:
  184. return [value.date(), value.time().replace(microsecond=0)]
  185. return [None, None]
  186. .. tip::
  187. Note that :class:`~django.forms.MultiValueField` has a
  188. complementary method :meth:`~django.forms.MultiValueField.compress`
  189. with the opposite responsibility - to combine cleaned values of
  190. all member fields into one.
  191. Other methods that may be useful to override include:
  192. .. method:: render(name, value, attrs=None)
  193. Argument ``value`` is handled differently in this method from the
  194. subclasses of :class:`~Widget` because it has to figure out how to
  195. split a single value for display in multiple widgets.
  196. The ``value`` argument used when rendering can be one of two things:
  197. * A ``list``.
  198. * A single value (e.g., a string) that is the "compressed" representation
  199. of a ``list`` of values.
  200. If `value` is a list, output of :meth:`~MultiWidget.render` will be a
  201. concatenation of rendered child widgets. If `value` is not a list, it
  202. will be first processed by the method :meth:`~MultiWidget.decompress()`
  203. to create the list and then processed as above.
  204. In the second case -- i.e., if the value is *not* a list --
  205. ``render()`` will first decompress the value into a ``list`` before
  206. rendering it. It does so by calling the ``decompress()`` method, which
  207. :class:`MultiWidget`'s subclasses must implement (see above).
  208. When ``render()`` executes its HTML rendering, each value in the list
  209. is rendered with the corresponding widget -- the first value is
  210. rendered in the first widget, the second value is rendered in the
  211. second widget, etc.
  212. Unlike in the single value widgets, method :meth:`~MultiWidget.render`
  213. need not be implemented in the subclasses.
  214. .. method:: format_output(rendered_widgets)
  215. Given a list of rendered widgets (as strings), returns a Unicode string
  216. representing the HTML for the whole lot.
  217. This hook allows you to format the HTML design of the widgets any way
  218. you'd like.
  219. Here's an example widget which subclasses :class:`MultiWidget` to display
  220. a date with the day, month, and year in different select boxes. This widget
  221. is intended to be used with a :class:`~django.forms.DateField` rather than
  222. a :class:`~django.forms.MultiValueField`, thus we have implemented
  223. :meth:`~Widget.value_from_datadict`::
  224. from datetime import date
  225. from django.forms import widgets
  226. class DateSelectorWidget(widgets.MultiWidget):
  227. def __init__(self, attrs=None):
  228. # create choices for days, months, years
  229. # example below, the rest snipped for brevity.
  230. years = [(year, year) for year in (2011, 2012, 2013)]
  231. _widgets = (
  232. widgets.Select(attrs=attrs, choices=days),
  233. widgets.Select(attrs=attrs, choices=months),
  234. widgets.Select(attrs=attrs, choices=years),
  235. )
  236. super(DateSelectorWidget, self).__init__(_widgets, attrs)
  237. def decompress(self, value):
  238. if value:
  239. return [value.day, value.month, value.year]
  240. return [None, None, None]
  241. def format_output(self, rendered_widgets):
  242. return u''.join(rendered_widgets)
  243. def value_from_datadict(self, data, files, name):
  244. datelist = [
  245. widget.value_from_datadict(data, files, name + '_%s' % i)
  246. for i, widget in enumerate(self.widgets)]
  247. try:
  248. D = date(day=int(datelist[0]), month=int(datelist[1]),
  249. year=int(datelist[2]))
  250. except ValueError:
  251. return ''
  252. else:
  253. return str(D)
  254. The constructor creates several :class:`Select` widgets in a tuple. The
  255. ``super`` class uses this tuple to setup the widget.
  256. The :meth:`~MultiWidget.format_output` method is fairly vanilla here (in
  257. fact, it's the same as what's been implemented as the default for
  258. ``MultiWidget``), but the idea is that you could add custom HTML between
  259. the widgets should you wish.
  260. The required method :meth:`~MultiWidget.decompress` breaks up a
  261. ``datetime.date`` value into the day, month, and year values corresponding
  262. to each widget. Note how the method handles the case where ``value`` is
  263. ``None``.
  264. The default implementation of :meth:`~Widget.value_from_datadict` returns
  265. a list of values corresponding to each ``Widget``. This is appropriate
  266. when using a ``MultiWidget`` with a :class:`~django.forms.MultiValueField`,
  267. but since we want to use this widget with a :class:`~django.forms.DateField`
  268. which takes a single value, we have overridden this method to combine the
  269. data of all the subwidgets into a ``datetime.date``. The method extracts
  270. data from the ``POST`` dictionary and constructs and validates the date.
  271. If it is valid, we return the string, otherwise, we return an empty string
  272. which will cause ``form.is_valid`` to return ``False``.
  273. .. _built-in widgets:
  274. Built-in widgets
  275. ----------------
  276. Django provides a representation of all the basic HTML widgets, plus some
  277. commonly used groups of widgets in the ``django.forms.widgets`` module,
  278. including :ref:`the input of text <text-widgets>`, :ref:`various checkboxes
  279. and selectors <selector-widgets>`, :ref:`uploading files <file-upload-widgets>`,
  280. and :ref:`handling of multi-valued input <composite-widgets>`.
  281. .. _text-widgets:
  282. Widgets handling input of text
  283. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  284. These widgets make use of the HTML elements ``input`` and ``textarea``.
  285. ``TextInput``
  286. ~~~~~~~~~~~~~
  287. .. class:: TextInput
  288. Text input: ``<input type='text' ...>``
  289. ``PasswordInput``
  290. ~~~~~~~~~~~~~~~~~
  291. .. class:: PasswordInput
  292. Password input: ``<input type='password' ...>``
  293. Takes one optional argument:
  294. .. attribute:: PasswordInput.render_value
  295. Determines whether the widget will have a value filled in when the
  296. form is re-displayed after a validation error (default is ``False``).
  297. ``HiddenInput``
  298. ~~~~~~~~~~~~~~~
  299. .. class:: HiddenInput
  300. Hidden input: ``<input type='hidden' ...>``
  301. Note that there also is a :class:`MultipleHiddenInput` widget that
  302. encapsulates a set of hidden input elements.
  303. ``DateInput``
  304. ~~~~~~~~~~~~~
  305. .. class:: DateInput
  306. Date input as a simple text box: ``<input type='text' ...>``
  307. Takes same arguments as :class:`TextInput`, with one more optional argument:
  308. .. attribute:: DateInput.format
  309. The format in which this field's initial value will be displayed.
  310. If no ``format`` argument is provided, the default format is the first
  311. format found in :setting:`DATE_INPUT_FORMATS` and respects
  312. :ref:`format-localization`.
  313. ``DateTimeInput``
  314. ~~~~~~~~~~~~~~~~~
  315. .. class:: DateTimeInput
  316. Date/time input as a simple text box: ``<input type='text' ...>``
  317. Takes same arguments as :class:`TextInput`, with one more optional argument:
  318. .. attribute:: DateTimeInput.format
  319. The format in which this field's initial value will be displayed.
  320. If no ``format`` argument is provided, the default format is the first
  321. format found in :setting:`DATETIME_INPUT_FORMATS` and respects
  322. :ref:`format-localization`.
  323. ``TimeInput``
  324. ~~~~~~~~~~~~~
  325. .. class:: TimeInput
  326. Time input as a simple text box: ``<input type='text' ...>``
  327. Takes same arguments as :class:`TextInput`, with one more optional argument:
  328. .. attribute:: TimeInput.format
  329. The format in which this field's initial value will be displayed.
  330. If no ``format`` argument is provided, the default format is the first
  331. format found in :setting:`TIME_INPUT_FORMATS` and respects
  332. :ref:`format-localization`.
  333. ``Textarea``
  334. ~~~~~~~~~~~~
  335. .. class:: Textarea
  336. Text area: ``<textarea>...</textarea>``
  337. .. _selector-widgets:
  338. Selector and checkbox widgets
  339. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  340. ``CheckboxInput``
  341. ~~~~~~~~~~~~~~~~~
  342. .. class:: CheckboxInput
  343. Checkbox: ``<input type='checkbox' ...>``
  344. Takes one optional argument:
  345. .. attribute:: CheckboxInput.check_test
  346. A callable that takes the value of the CheckBoxInput and returns
  347. ``True`` if the checkbox should be checked for that value.
  348. .. versionchanged:: 1.5
  349. Exceptions from ``check_test`` used to be silenced by its caller,
  350. this is no longer the case, they will propagate upwards.
  351. ``Select``
  352. ~~~~~~~~~~
  353. .. class:: Select
  354. Select widget: ``<select><option ...>...</select>``
  355. .. attribute:: Select.choices
  356. This attribute is optional when the field does not have a
  357. :attr:`~Field.choices` attribute. If it does, it will override anything
  358. you set here when the attribute is updated on the :class:`Field`.
  359. ``NullBooleanSelect``
  360. ~~~~~~~~~~~~~~~~~~~~~
  361. .. class:: NullBooleanSelect
  362. Select widget with options 'Unknown', 'Yes' and 'No'
  363. ``SelectMultiple``
  364. ~~~~~~~~~~~~~~~~~~
  365. .. class:: SelectMultiple
  366. Similar to :class:`Select`, but allows multiple selection:
  367. ``<select multiple='multiple'>...</select>``
  368. ``RadioSelect``
  369. ~~~~~~~~~~~~~~~
  370. .. class:: RadioSelect
  371. Similar to :class:`Select`, but rendered as a list of radio buttons within
  372. ``<li>`` tags:
  373. .. code-block:: html
  374. <ul>
  375. <li><input type='radio' ...></li>
  376. ...
  377. </ul>
  378. .. versionadded:: 1.4
  379. For more granular control over the generated markup, you can loop over the
  380. radio buttons in the template. Assuming a form ``myform`` with a field
  381. ``beatles`` that uses a ``RadioSelect`` as its widget:
  382. .. code-block:: html+django
  383. {% for radio in myform.beatles %}
  384. <div class="myradio">
  385. {{ radio }}
  386. </div>
  387. {% endfor %}
  388. This would generate the following HTML:
  389. .. code-block:: html
  390. <div class="myradio">
  391. <label><input type="radio" name="beatles" value="john" /> John</label>
  392. </div>
  393. <div class="myradio">
  394. <label><input type="radio" name="beatles" value="paul" /> Paul</label>
  395. </div>
  396. <div class="myradio">
  397. <label><input type="radio" name="beatles" value="george" /> George</label>
  398. </div>
  399. <div class="myradio">
  400. <label><input type="radio" name="beatles" value="ringo" /> Ringo</label>
  401. </div>
  402. That included the ``<label>`` tags. To get more granular, you can use each
  403. radio button's ``tag`` and ``choice_label`` attributes. For example, this template...
  404. .. code-block:: html+django
  405. {% for radio in myform.beatles %}
  406. <label>
  407. {{ radio.choice_label }}
  408. <span class="radio">{{ radio.tag }}</span>
  409. </label>
  410. {% endfor %}
  411. ...will result in the following HTML:
  412. .. code-block:: html
  413. <label>
  414. John
  415. <span class="radio"><input type="radio" name="beatles" value="john" /></span>
  416. </label>
  417. <label>
  418. Paul
  419. <span class="radio"><input type="radio" name="beatles" value="paul" /></span>
  420. </label>
  421. <label>
  422. George
  423. <span class="radio"><input type="radio" name="beatles" value="george" /></span>
  424. </label>
  425. <label>
  426. Ringo
  427. <span class="radio"><input type="radio" name="beatles" value="ringo" /></span>
  428. </label>
  429. If you decide not to loop over the radio buttons -- e.g., if your template simply includes
  430. ``{{ myform.beatles }}`` -- they'll be output in a ``<ul>`` with ``<li>`` tags, as above.
  431. ``CheckboxSelectMultiple``
  432. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  433. .. class:: CheckboxSelectMultiple
  434. Similar to :class:`SelectMultiple`, but rendered as a list of check
  435. buttons:
  436. .. code-block:: html
  437. <ul>
  438. <li><input type='checkbox' ...></li>
  439. ...
  440. </ul>
  441. .. _file-upload-widgets:
  442. File upload widgets
  443. ^^^^^^^^^^^^^^^^^^^
  444. ``FileInput``
  445. ~~~~~~~~~~~~~
  446. .. class:: FileInput
  447. File upload input: ``<input type='file' ...>``
  448. ``ClearableFileInput``
  449. ~~~~~~~~~~~~~~~~~~~~~~
  450. .. class:: ClearableFileInput
  451. File upload input: ``<input type='file' ...>``, with an additional checkbox
  452. input to clear the field's value, if the field is not required and has
  453. initial data.
  454. .. _composite-widgets:
  455. Composite widgets
  456. ^^^^^^^^^^^^^^^^^
  457. ``MultipleHiddenInput``
  458. ~~~~~~~~~~~~~~~~~~~~~~~
  459. .. class:: MultipleHiddenInput
  460. Multiple ``<input type='hidden' ...>`` widgets.
  461. A widget that handles multiple hidden widgets for fields that have a list
  462. of values.
  463. .. attribute:: MultipleHiddenInput.choices
  464. This attribute is optional when the field does not have a
  465. :attr:`~Field.choices` attribute. If it does, it will override anything
  466. you set here when the attribute is updated on the :class:`Field`.
  467. ``SplitDateTimeWidget``
  468. ~~~~~~~~~~~~~~~~~~~~~~~
  469. .. class:: SplitDateTimeWidget
  470. Wrapper (using :class:`MultiWidget`) around two widgets: :class:`DateInput`
  471. for the date, and :class:`TimeInput` for the time.
  472. ``SplitDateTimeWidget`` has two optional attributes:
  473. .. attribute:: SplitDateTimeWidget.date_format
  474. Similar to :attr:`DateInput.format`
  475. .. attribute:: SplitDateTimeWidget.time_format
  476. Similar to :attr:`TimeInput.format`
  477. ``SplitHiddenDateTimeWidget``
  478. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  479. .. class:: SplitHiddenDateTimeWidget
  480. Similar to :class:`SplitDateTimeWidget`, but uses :class:`HiddenInput` for
  481. both date and time.
  482. .. currentmodule:: django.forms.extras.widgets
  483. ``SelectDateWidget``
  484. ~~~~~~~~~~~~~~~~~~~~
  485. .. class:: SelectDateWidget
  486. Wrapper around three :class:`~django.forms.Select` widgets: one each for
  487. month, day, and year. Note that this widget lives in a separate file from
  488. the standard widgets.
  489. Takes one optional argument:
  490. .. attribute:: SelectDateWidget.years
  491. An optional list/tuple of years to use in the "year" select box.
  492. The default is a list containing the current year and the next 9 years.