summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-05-18 07:30:42 -0700
committerTim Graham <timograham@gmail.com>2016-06-13 09:14:36 -0400
commit267dc4adddd2882182f71a7f285a06b1d4b15af0 (patch)
tree085fbeac6fa9139c5214bc16b46535cde690733d /docs
parentf2c0eb19e961f5864573251e70bdcdecd0250aed (diff)
Fixed #4136 -- Made ModelForm save empty values for nullable CharFields as NULL.
Previously, empty values were saved as strings.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/forms/fields.txt8
-rw-r--r--docs/ref/models/fields.txt8
-rw-r--r--docs/releases/1.11.txt10
-rw-r--r--docs/topics/forms/modelforms.txt4
4 files changed, 24 insertions, 6 deletions
diff --git a/docs/ref/forms/fields.txt b/docs/ref/forms/fields.txt
index 7144a46a9d..0a5703c46e 100644
--- a/docs/ref/forms/fields.txt
+++ b/docs/ref/forms/fields.txt
@@ -361,7 +361,7 @@ For each field, we describe the default widget used if you don't specify
.. class:: CharField(**kwargs)
* Default widget: :class:`TextInput`
- * Empty value: ``''`` (an empty string)
+ * Empty value: Whatever you've given as :attr:`empty_value`.
* Normalizes to: A Unicode object.
* Validates ``max_length`` or ``min_length``, if they are provided.
Otherwise, all inputs are valid.
@@ -380,6 +380,12 @@ For each field, we describe the default widget used if you don't specify
If ``True`` (default), the value will be stripped of leading and
trailing whitespace.
+ .. attribute:: empty_value
+
+ .. versionadded:: 1.11
+
+ The value to use to represent "empty". Defaults to an empty string.
+
``ChoiceField``
---------------
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index a56c445c31..2435201db8 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -43,11 +43,13 @@ If ``True``, Django will store empty values as ``NULL`` in the database. Default
is ``False``.
Avoid using :attr:`~Field.null` on string-based fields such as
-:class:`CharField` and :class:`TextField` because empty string values will
-always be stored as empty strings, not as ``NULL``. If a string-based field has
+:class:`CharField` and :class:`TextField`. If a string-based field has
``null=True``, that means it has two possible values for "no data": ``NULL``,
and the empty string. In most cases, it's redundant to have two possible values
-for "no data;" the Django convention is to use the empty string, not ``NULL``.
+for "no data;" the Django convention is to use the empty string, not
+``NULL``. One exception is when a :class:`CharField` has both ``unique=True``
+and ``blank=True`` set. In this situation, ``null=True`` is required to avoid
+unique constraint violations when saving multiple objects with blank values.
For both string-based and non-string-based fields, you will also need to
set ``blank=True`` if you wish to permit empty values in forms, as the
diff --git a/docs/releases/1.11.txt b/docs/releases/1.11.txt
index d2e3e74fdd..709c4052f1 100644
--- a/docs/releases/1.11.txt
+++ b/docs/releases/1.11.txt
@@ -154,7 +154,8 @@ File Uploads
Forms
~~~~~
-* ...
+* The new :attr:`CharField.empty_value <django.forms.CharField.empty_value>`
+ attribute allows specifying the Python value to use to represent "empty".
Generic Views
~~~~~~~~~~~~~
@@ -258,6 +259,13 @@ Miscellaneous
displays the related object's ID. Remove the ``_id`` suffix if you want the
old behavior of the string representation of the object.
+* In model forms, :class:`~django.db.models.CharField` with ``null=True`` now
+ saves ``NULL`` for blank values instead of empty strings.
+
+* On Oracle, :meth:`Model.validate_unique()
+ <django.db.models.Model.validate_unique>` no longer checks empty strings for
+ uniqueness as the database interprets the value as ``NULL``.
+
.. _deprecated-features-1.11:
Features deprecated in 1.11
diff --git a/docs/topics/forms/modelforms.txt b/docs/topics/forms/modelforms.txt
index 938516050a..9dcb2e3e53 100644
--- a/docs/topics/forms/modelforms.txt
+++ b/docs/topics/forms/modelforms.txt
@@ -66,7 +66,9 @@ Model field Form field
:class:`CharField` :class:`~django.forms.CharField` with
``max_length`` set to the model field's
- ``max_length``
+ ``max_length`` and
+ :attr:`~django.forms.CharField.empty_value`
+ set to ``None`` if ``null=True``.
:class:`CommaSeparatedIntegerField` :class:`~django.forms.CharField`