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.
This commit is contained in:
Simon Charette 2024-02-26 00:14:26 -05:00 committed by Mariusz Felisiak
parent f82c67aa21
commit daf7d482db
21 changed files with 210 additions and 136 deletions

View file

@ -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``
====================