mirror of
https://github.com/django/django.git
synced 2025-08-30 23:37:50 +00:00
Added a TypedChoiceField
which acts just like ChoiceField
, except that it
returns a value coerced by some provided function. Refs #6967. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8771 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3e71a684b3
commit
4ae746b574
3 changed files with 103 additions and 0 deletions
|
@ -362,6 +362,33 @@ Takes one extra required argument:
|
|||
|
||||
An iterable (e.g., a list or tuple) of 2-tuples to use as choices for this
|
||||
field.
|
||||
|
||||
``TypedChoiceField``
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. class:: TypedChoiceField(**kwargs)
|
||||
|
||||
Just like a :class:`ChoiceField`, except :class:`TypedChoiceField` takes an
|
||||
extra ``coerce`` argument.
|
||||
|
||||
* Default widget: ``Select``
|
||||
* Empty value: Whatever you've given as ``empty_value``
|
||||
* Normalizes to: the value returned by the ``coerce`` argument.
|
||||
* Validates that the given value exists in the list of choices.
|
||||
* Error message keys: ``required``, ``invalid_choice``
|
||||
|
||||
Takes extra arguments:
|
||||
|
||||
.. attribute:: TypedChoiceField.coerce
|
||||
|
||||
A function that takes one argument and returns a coerced value. Examples
|
||||
include the built-in ``int``, ``float``, ``bool`` and other types. Defaults
|
||||
to an identity function.
|
||||
|
||||
.. attribute:: TypedChoiceField.empty_value
|
||||
|
||||
The value to use to represent "empty." Defaults to the empty string;
|
||||
``None`` is another common choice here.
|
||||
|
||||
``DateField``
|
||||
~~~~~~~~~~~~~
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue