1
0
mirror of https://github.com/django/django.git synced 2025-08-25 19:29:14 +00:00

[5.2.x] Aligned format of constraint examples in docs/ref/models/constraints.txt.

Backport of fda3c1712a1eb7b20dfc91e6c9abae32bd64d081 from main.
This commit is contained in:
David Sanders 2025-08-12 01:32:24 +10:00 committed by Sarah Boyce
parent 1d9f6c3270
commit 4926591343

View File

@ -26,8 +26,9 @@ option.
(including ``name``) each time. To work around name collisions, part of the (including ``name``) each time. To work around name collisions, part of the
name may contain ``'%(app_label)s'`` and ``'%(class)s'``, which are name may contain ``'%(app_label)s'`` and ``'%(class)s'``, which are
replaced, respectively, by the lowercased app label and class name of the replaced, respectively, by the lowercased app label and class name of the
concrete model. For example ``CheckConstraint(condition=Q(age__gte=18), concrete model. For example::
name='%(app_label)s_%(class)s_is_adult')``.
CheckConstraint(condition=Q(age__gte=18), name="%(app_label)s_%(class)s_is_adult")
.. admonition:: Validation of Constraints .. admonition:: Validation of Constraints
@ -103,7 +104,10 @@ This method must be implemented by a subclass.
A :class:`Q` object or boolean :class:`~django.db.models.Expression` that A :class:`Q` object or boolean :class:`~django.db.models.Expression` that
specifies the conditional check you want the constraint to enforce. specifies the conditional check you want the constraint to enforce.
For example, ``CheckConstraint(condition=Q(age__gte=18), name='age_gte_18')`` For example::
CheckConstraint(condition=Q(age__gte=18), name="age_gte_18")
ensures the age field is never less than 18. ensures the age field is never less than 18.
.. admonition:: Expression order .. admonition:: Expression order
@ -164,9 +168,11 @@ Functional unique constraints have the same database restrictions as
A list of field names that specifies the unique set of columns you want the A list of field names that specifies the unique set of columns you want the
constraint to enforce. constraint to enforce.
For example, ``UniqueConstraint(fields=['room', 'date'], For example::
name='unique_booking')`` ensures each room can only be booked once for each
date. UniqueConstraint(fields=["room", "date"], name="unique_booking")
ensures each room can only be booked once for each date.
``condition`` ``condition``
------------- -------------