diff options
| author | Simon Charette <charette.s@gmail.com> | 2024-02-26 00:14:26 -0500 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2024-03-01 07:15:32 +0100 |
| commit | daf7d482dbaaa2604241a994c49f442fa15142c1 (patch) | |
| tree | 65eae557dbe8694e03130cc17259a792792c95b7 /docs/ref | |
| parent | f82c67aa217c8dd4320ef697b04a6da1681aa799 (diff) | |
Refs #35234 -- Deprecated CheckConstraint.check in favor of .condition.
Once the deprecation period ends CheckConstraint.check() can become the
documented method that performs system checks for BaseConstraint
subclasses.
Diffstat (limited to 'docs/ref')
| -rw-r--r-- | docs/ref/models/constraints.txt | 22 | ||||
| -rw-r--r-- | docs/ref/models/options.txt | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index 0d6d87afbe..fa6edfd766 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -26,7 +26,7 @@ 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(check=Q(age__gte=18), + concrete model. For example ``CheckConstraint(condition=Q(age__gte=18), name='%(app_label)s_%(class)s_is_adult')``. .. admonition:: Validation of Constraints @@ -104,19 +104,19 @@ This method must be implemented by a subclass. ``CheckConstraint`` =================== -.. class:: CheckConstraint(*, check, name, violation_error_code=None, violation_error_message=None) +.. class:: CheckConstraint(*, condition, name, violation_error_code=None, violation_error_message=None) Creates a check constraint in the database. -``check`` ---------- +``condition`` +------------- -.. attribute:: CheckConstraint.check +.. attribute:: CheckConstraint.condition A :class:`Q` object or boolean :class:`~django.db.models.Expression` that -specifies the check you want the constraint to enforce. +specifies the conditional check you want the constraint to enforce. -For example, ``CheckConstraint(check=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 @@ -127,7 +127,7 @@ ensures the age field is never less than 18. reasons. For example, use the following format if order matters:: CheckConstraint( - check=Q(age__gte=18) & Q(expensive_check=condition), + condition=Q(age__gte=18) & Q(expensive_check=condition), name="age_gte_18_and_others", ) @@ -138,7 +138,11 @@ ensures the age field is never less than 18. to behave the same as check constraints validation. For example, if ``age`` is a nullable field:: - CheckConstraint(check=Q(age__gte=18) | Q(age__isnull=True), name="age_gte_18") + CheckConstraint(condition=Q(age__gte=18) | Q(age__isnull=True), name="age_gte_18") + +.. deprecated:: 5.1 + + The ``check`` attribute is deprecated in favor of ``condition``. ``UniqueConstraint`` ==================== diff --git a/docs/ref/models/options.txt b/docs/ref/models/options.txt index 909577be6c..3433d0730f 100644 --- a/docs/ref/models/options.txt +++ b/docs/ref/models/options.txt @@ -467,7 +467,7 @@ not be looking at your Django code. For example:: class Meta: constraints = [ - models.CheckConstraint(check=models.Q(age__gte=18), name="age_gte_18"), + models.CheckConstraint(condition=models.Q(age__gte=18), name="age_gte_18"), ] ``verbose_name`` |
