diff options
| author | David Sanders <shang.xiao.sanders@gmail.com> | 2025-08-12 01:32:24 +1000 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-08-13 09:09:19 +0200 |
| commit | fda3c1712a1eb7b20dfc91e6c9abae32bd64d081 (patch) | |
| tree | bef4b26cd908461b4eed2a37debd4f6fdd314275 /docs | |
| parent | a9b07cec03ccb3ba3f1cb47572c779d986b6dd06 (diff) | |
Aligned format of constraint examples in docs/ref/models/constraints.txt.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/ref/models/constraints.txt | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index f7549c0252..eefe741805 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -26,8 +26,9 @@ option. (including ``name``) each time. To work around name collisions, part of the name may contain ``'%(app_label)s'`` and ``'%(class)s'``, which are replaced, respectively, by the lowercased app label and class name of the - concrete model. For example ``CheckConstraint(condition=Q(age__gte=18), - name='%(app_label)s_%(class)s_is_adult')``. + concrete model. For example:: + + CheckConstraint(condition=Q(age__gte=18), name="%(app_label)s_%(class)s_is_adult") .. admonition:: Validation of Constraints @@ -99,7 +100,10 @@ This method must be implemented by a subclass. A :class:`Q` object or boolean :class:`~django.db.models.Expression` that 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. .. admonition:: Expression order @@ -156,9 +160,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 constraint to enforce. -For example, ``UniqueConstraint(fields=['room', 'date'], -name='unique_booking')`` ensures each room can only be booked once for each -date. +For example:: + + UniqueConstraint(fields=["room", "date"], name="unique_booking") + +ensures each room can only be booked once for each date. ``condition`` ------------- |
