Fixed #28009 -- Doc'd empty_value for CharField subclasses.

This commit is contained in:
David Smith 2020-07-04 07:58:11 +01:00 committed by Mariusz Felisiak
parent b8239cae19
commit 91669cc566
2 changed files with 21 additions and 20 deletions

View File

@ -89,7 +89,8 @@ To specify that a field is *not* required, pass ``required=False`` to the
If a ``Field`` has ``required=False`` and you pass ``clean()`` an empty value, If a ``Field`` has ``required=False`` and you pass ``clean()`` an empty value,
then ``clean()`` will return a *normalized* empty value rather than raising then ``clean()`` will return a *normalized* empty value rather than raising
``ValidationError``. For ``CharField``, this will be an empty string. For other ``ValidationError``. For ``CharField``, this will return
:attr:`~CharField.empty_value` which defaults to an empty string. For other
``Field`` classes, it might be ``None``. (This varies from field to field.) ``Field`` classes, it might be ``None``. (This varies from field to field.)
Widgets of required form fields have the ``required`` HTML attribute. Set the Widgets of required form fields have the ``required`` HTML attribute. Set the
@ -582,16 +583,15 @@ For each field, we describe the default widget used if you don't specify
.. class:: EmailField(**kwargs) .. class:: EmailField(**kwargs)
* Default widget: :class:`EmailInput` * Default widget: :class:`EmailInput`
* Empty value: ``''`` (an empty string) * Empty value: Whatever you've given as ``empty_value``.
* Normalizes to: A string. * Normalizes to: A string.
* Uses :class:`~django.core.validators.EmailValidator` to validate that * Uses :class:`~django.core.validators.EmailValidator` to validate that
the given value is a valid email address, using a moderately complex the given value is a valid email address, using a moderately complex
regular expression. regular expression.
* Error message keys: ``required``, ``invalid`` * Error message keys: ``required``, ``invalid``
Has two optional arguments for validation, ``max_length`` and ``min_length``. Has three optional arguments ``max_length``, ``min_length``, and
If provided, these arguments ensure that the string is at most or at least the ``empty_value`` which work just as they do for :class:`CharField`.
given length.
``FileField`` ``FileField``
------------- -------------
@ -919,7 +919,7 @@ For each field, we describe the default widget used if you don't specify
.. class:: RegexField(**kwargs) .. class:: RegexField(**kwargs)
* Default widget: :class:`TextInput` * Default widget: :class:`TextInput`
* Empty value: ``''`` (an empty string) * Empty value: Whatever you've given as ``empty_value``.
* Normalizes to: A string. * Normalizes to: A string.
* Uses :class:`~django.core.validators.RegexValidator` to validate that * Uses :class:`~django.core.validators.RegexValidator` to validate that
the given value matches a certain regular expression. the given value matches a certain regular expression.
@ -932,8 +932,8 @@ For each field, we describe the default widget used if you don't specify
A regular expression specified either as a string or a compiled regular A regular expression specified either as a string or a compiled regular
expression object. expression object.
Also takes ``max_length``, ``min_length``, and ``strip``, which work just Also takes ``max_length``, ``min_length``, ``strip``, and ``empty_value``
as they do for :class:`CharField`. which work just as they do for :class:`CharField`.
.. attribute:: strip .. attribute:: strip
@ -946,7 +946,7 @@ For each field, we describe the default widget used if you don't specify
.. class:: SlugField(**kwargs) .. class:: SlugField(**kwargs)
* Default widget: :class:`TextInput` * Default widget: :class:`TextInput`
* Empty value: ``''`` (an empty string) * Empty value: Whatever you've given as :attr:`empty_value`.
* Normalizes to: A string. * Normalizes to: A string.
* Uses :class:`~django.core.validators.validate_slug` or * Uses :class:`~django.core.validators.validate_slug` or
:class:`~django.core.validators.validate_unicode_slug` to validate that :class:`~django.core.validators.validate_unicode_slug` to validate that
@ -956,13 +956,17 @@ For each field, we describe the default widget used if you don't specify
This field is intended for use in representing a model This field is intended for use in representing a model
:class:`~django.db.models.SlugField` in forms. :class:`~django.db.models.SlugField` in forms.
Takes an optional parameter: Takes two optional parameters:
.. attribute:: allow_unicode .. attribute:: allow_unicode
A boolean instructing the field to accept Unicode letters in addition A boolean instructing the field to accept Unicode letters in addition
to ASCII letters. Defaults to ``False``. to ASCII letters. Defaults to ``False``.
.. attribute:: empty_value
The value to use to represent "empty". Defaults to an empty string.
``TimeField`` ``TimeField``
------------- -------------
@ -994,19 +998,14 @@ For each field, we describe the default widget used if you don't specify
.. class:: URLField(**kwargs) .. class:: URLField(**kwargs)
* Default widget: :class:`URLInput` * Default widget: :class:`URLInput`
* Empty value: ``''`` (an empty string) * Empty value: Whatever you've given as ``empty_value``.
* Normalizes to: A string. * Normalizes to: A string.
* Uses :class:`~django.core.validators.URLValidator` to validate that the * Uses :class:`~django.core.validators.URLValidator` to validate that the
given value is a valid URL. given value is a valid URL.
* Error message keys: ``required``, ``invalid`` * Error message keys: ``required``, ``invalid``
Takes the following optional arguments: Has three optional arguments ``max_length``, ``min_length``, and
``empty_value`` which work just as they do for :class:`CharField`.
.. attribute:: max_length
.. attribute:: min_length
These are the same as ``CharField.max_length`` and
``CharField.min_length``.
``UUIDField`` ``UUIDField``
------------- -------------

View File

@ -288,8 +288,10 @@ File Storage
Forms Forms
~~~~~ ~~~~~
* The new :attr:`CharField.empty_value <django.forms.CharField.empty_value>` * The new ``empty_value`` attribute on :class:`~django.forms.CharField`,
attribute allows specifying the Python value to use to represent "empty". :class:`~django.forms.EmailField`, :class:`~django.forms.RegexField`,
:class:`~django.forms.SlugField`, and :class:`~django.forms.URLField` allows
specifying the Python value to use to represent "empty".
* The new :meth:`Form.get_initial_for_field() * The new :meth:`Form.get_initial_for_field()
<django.forms.Form.get_initial_for_field>` method returns initial data for a <django.forms.Form.get_initial_for_field>` method returns initial data for a