summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorYash <yashraj504300@gmail.com>2024-10-16 14:38:31 +0530
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-10-23 11:51:13 +0200
commit630c9e1f9d05e9d25908a0c5d5f81f1b0b537af0 (patch)
tree99b8f32ab7d2f7dcef4ad7d308df9c39ec83800a /docs
parentd9f37ac118e1717f831394d2be3b64c712d3b40e (diff)
[5.1.x] Fixed #35731 -- Extended db_default docs.
This added a missing db_default reference in docs/topics/db/models.txt, and added a reference to the DatabaseDefault object. Backport of 35ab2e018214479fa712d73f070198299ef670a1 from main.
Diffstat (limited to 'docs')
-rw-r--r--docs/ref/models/fields.txt5
-rw-r--r--docs/topics/db/models.txt9
2 files changed, 14 insertions, 0 deletions
diff --git a/docs/ref/models/fields.txt b/docs/ref/models/fields.txt
index 0ceb620a9f..745520961d 100644
--- a/docs/ref/models/fields.txt
+++ b/docs/ref/models/fields.txt
@@ -434,6 +434,11 @@ precedence when creating instances in Python code. ``db_default`` will still be
set at the database level and will be used when inserting rows outside of the
ORM or when adding a new field in a migration.
+If a field has a ``db_default`` without a ``default`` set and no value is
+assigned to the field, a ``DatabaseDefault`` object is returned as the field
+value on unsaved model instances. The actual value for the field is determined
+by the database when the model instance is saved.
+
``db_index``
------------
diff --git a/docs/topics/db/models.txt b/docs/topics/db/models.txt
index ee4bdab7bb..62488a75f7 100644
--- a/docs/topics/db/models.txt
+++ b/docs/topics/db/models.txt
@@ -228,6 +228,15 @@ ones:
object. If callable it will be called every time a new object is
created.
+:attr:`~Field.db_default`
+ The database-computed default value for the field. This can be a literal
+ value or a database function.
+
+ If both ``db_default`` and :attr:`Field.default` are set, ``default`` will
+ take precedence when creating instances in Python code. ``db_default`` will
+ still be set at the database level and will be used when inserting rows
+ outside of the ORM or when adding a new field in a migration.
+
:attr:`~Field.help_text`
Extra "help" text to be displayed with the form widget. It's useful for
documentation even if your field isn't used on a form.