Skip to content

Commit 35ab2e0

Browse files
YashRaj1506sarahboyce
authored andcommitted
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.
1 parent 04adff9 commit 35ab2e0

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

docs/ref/models/fields.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,11 @@ precedence when creating instances in Python code. ``db_default`` will still be
426426
set at the database level and will be used when inserting rows outside of the
427427
ORM or when adding a new field in a migration.
428428

429+
If a field has a ``db_default`` without a ``default`` set and no value is
430+
assigned to the field, a ``DatabaseDefault`` object is returned as the field
431+
value on unsaved model instances. The actual value for the field is determined
432+
by the database when the model instance is saved.
433+
429434
``db_index``
430435
------------
431436

docs/topics/db/models.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,15 @@ ones:
224224
object. If callable it will be called every time a new object is
225225
created.
226226

227+
:attr:`~Field.db_default`
228+
The database-computed default value for the field. This can be a literal
229+
value or a database function.
230+
231+
If both ``db_default`` and :attr:`Field.default` are set, ``default`` will
232+
take precedence when creating instances in Python code. ``db_default`` will
233+
still be set at the database level and will be used when inserting rows
234+
outside of the ORM or when adding a new field in a migration.
235+
227236
:attr:`~Field.help_text`
228237
Extra "help" text to be displayed with the form widget. It's useful for
229238
documentation even if your field isn't used on a form.

0 commit comments

Comments
 (0)