mirror of
https://github.com/django/django.git
synced 2025-07-24 13:44:32 +00:00
Fixed #8962 -- Consistently support format and input_format in the various (individual, combined, split) date and time form fields and widgets.
Many thanks to Tai Lee for doing all the work here. git-svn-id: http://code.djangoproject.com/svn/django/trunk@10115 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
b203db6ec8
commit
14b160957e
8 changed files with 177 additions and 17 deletions
|
@ -66,9 +66,9 @@ Countries currently supported by :mod:`~django.contrib.localflavor` are:
|
|||
* `United States of America`_
|
||||
|
||||
The ``django.contrib.localflavor`` package also includes a ``generic`` subpackage,
|
||||
containing useful code that is not specific to one particular country or
|
||||
culture. Currently, it defines date and datetime input fields based on those
|
||||
from :ref:`forms <topics-forms-index>`, but with non-US default formats.
|
||||
containing useful code that is not specific to one particular country or culture.
|
||||
Currently, it defines date, datetime and split datetime input fields based on
|
||||
those from :ref:`forms <topics-forms-index>`, but with non-US default formats.
|
||||
Here's an example of how to use them::
|
||||
|
||||
from django import forms
|
||||
|
|
|
@ -398,7 +398,7 @@ Takes extra arguments:
|
|||
|
||||
.. class:: DateField(**kwargs)
|
||||
|
||||
* Default widget: ``TextInput``
|
||||
* Default widget: ``DateInput``
|
||||
* Empty value: ``None``
|
||||
* Normalizes to: A Python ``datetime.date`` object.
|
||||
* Validates that the given value is either a ``datetime.date``,
|
||||
|
@ -420,6 +420,10 @@ If no ``input_formats`` argument is provided, the default input formats are::
|
|||
'%B %d %Y', '%B %d, %Y', # 'October 25 2006', 'October 25, 2006'
|
||||
'%d %B %Y', '%d %B, %Y', # '25 October 2006', '25 October, 2006'
|
||||
|
||||
.. versionchanged:: 1.1
|
||||
The ``DateField`` previously used a ``TextInput`` widget by default. It now
|
||||
uses a ``DateInput`` widget.
|
||||
|
||||
``DateTimeField``
|
||||
~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -739,6 +743,36 @@ The following are not yet documented.
|
|||
|
||||
.. class:: SplitDateTimeField(**kwargs)
|
||||
|
||||
* Default widget: ``SplitDateTimeWidget``
|
||||
* Empty value: ``None``
|
||||
* Normalizes to: A Python ``datetime.datetime`` object.
|
||||
* Validates that the given value is a ``datetime.datetime`` or string
|
||||
formatted in a particular datetime format.
|
||||
* Error message keys: ``required``, ``invalid``
|
||||
|
||||
Takes two optional arguments:
|
||||
|
||||
.. attribute:: SplitDateTimeField.input_date_formats
|
||||
|
||||
A list of formats used to attempt to convert a string to a valid
|
||||
``datetime.date`` object.
|
||||
|
||||
If no ``input_date_formats`` argument is provided, the default input formats
|
||||
for ``DateField`` are used.
|
||||
|
||||
.. attribute:: SplitDateTimeField.input_time_formats
|
||||
|
||||
A list of formats used to attempt to convert a string to a valid
|
||||
``datetime.time`` object.
|
||||
|
||||
If no ``input_time_formats`` argument is provided, the default input formats
|
||||
for ``TimeField`` are used.
|
||||
|
||||
.. versionchanged:: 1.1
|
||||
The ``SplitDateTimeField`` previously used two ``TextInput`` widgets by
|
||||
default. The ``input_date_formats`` and ``input_time_formats`` arguments
|
||||
are also new.
|
||||
|
||||
Fields which handle relationships
|
||||
---------------------------------
|
||||
|
||||
|
|
|
@ -36,12 +36,49 @@ commonly used groups of widgets:
|
|||
|
||||
File upload input: ``<input type='file' ...>``
|
||||
|
||||
.. class:: DateInput
|
||||
|
||||
.. versionadded:: 1.1
|
||||
|
||||
Date input as a simple text box: ``<input type='text' ...>``
|
||||
|
||||
Takes one optional argument:
|
||||
|
||||
.. attribute:: DateInput.format
|
||||
|
||||
The format in which this field's initial value will be displayed.
|
||||
|
||||
If no ``format`` argument is provided, the default format is ``'%Y-%m-%d'``.
|
||||
|
||||
.. class:: DateTimeInput
|
||||
|
||||
.. versionadded:: 1.0
|
||||
|
||||
Date/time input as a simple text box: ``<input type='text' ...>``
|
||||
|
||||
Takes one optional argument:
|
||||
|
||||
.. attribute:: DateTimeInput.format
|
||||
|
||||
The format in which this field's initial value will be displayed.
|
||||
|
||||
If no ``format`` argument is provided, the default format is ``'%Y-%m-%d %H:%M:%S'``.
|
||||
|
||||
.. class:: TimeInput
|
||||
|
||||
Time input as a simple text box: ``<input type='text' ...>``
|
||||
|
||||
Takes one optional argument:
|
||||
|
||||
.. attribute:: TimeInput.format
|
||||
|
||||
The format in which this field's initial value will be displayed.
|
||||
|
||||
If no ``format`` argument is provided, the default format is ``'%H:%M:%S'``.
|
||||
|
||||
.. versionchanged:: 1.1
|
||||
The ``format`` argument was not supported in Django 1.0.
|
||||
|
||||
.. class:: Textarea
|
||||
|
||||
Text area: ``<textarea>...</textarea>``
|
||||
|
@ -91,8 +128,15 @@ commonly used groups of widgets:
|
|||
|
||||
.. class:: SplitDateTimeWidget
|
||||
|
||||
Wrapper around two ``TextInput`` widgets: one for the date, and one for the
|
||||
time.
|
||||
Wrapper around two widgets: ``DateInput`` for the date, and ``TimeInput``
|
||||
for the time.
|
||||
|
||||
Takes two optional arguments, ``date_format`` and ``time_format``, which
|
||||
work just like the ``format`` argument for ``DateInput`` and ``TimeInput``.
|
||||
|
||||
.. versionchanged:: 1.1
|
||||
The ``date_format`` and ``time_format`` arguments were not supported in Django 1.0.
|
||||
|
||||
|
||||
Specifying widgets
|
||||
------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue