From febe136d4c3310ec8901abecca3ea5ba2be3952c Mon Sep 17 00:00:00 2001 From: can Date: Fri, 5 Jul 2019 15:15:41 +0300 Subject: Fixed #30397 -- Added app_label/class interpolation for names of indexes and constraints. --- docs/ref/models/constraints.txt | 15 +++++++++++++-- docs/ref/models/indexes.txt | 10 ++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) (limited to 'docs/ref') diff --git a/docs/ref/models/constraints.txt b/docs/ref/models/constraints.txt index d172353326..b5b77b8654 100644 --- a/docs/ref/models/constraints.txt +++ b/docs/ref/models/constraints.txt @@ -25,8 +25,11 @@ option. cannot normally specify a constraint on an abstract base class, since the :attr:`Meta.constraints ` option is inherited by subclasses, with exactly the same values for the attributes - (including ``name``) each time. Instead, specify the ``constraints`` option - on subclasses directly, providing a unique name for each constraint. + (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), + name='%(app_label)s_%(class)s_is_adult')``. .. admonition:: Validation of Constraints @@ -63,6 +66,10 @@ ensures the age field is never less than 18. The name of the constraint. +.. versionchanged:: 3.0 + + Interpolation of ``'%(app_label)s'`` and ``'%(class)s'`` was added. + ``UniqueConstraint`` ==================== @@ -89,6 +96,10 @@ date. The name of the constraint. +.. versionchanged:: 3.0 + + Interpolation of ``'%(app_label)s'`` and ``'%(class)s'`` was added. + ``condition`` ------------- diff --git a/docs/ref/models/indexes.txt b/docs/ref/models/indexes.txt index 13e37f78c7..5909ee9c64 100644 --- a/docs/ref/models/indexes.txt +++ b/docs/ref/models/indexes.txt @@ -55,9 +55,15 @@ than 30 characters and shouldn't start with a number (0-9) or underscore (_). cannot normally specify a partial index on an abstract base class, since the :attr:`Meta.indexes ` option is inherited by subclasses, with exactly the same values for the attributes - (including ``name``) each time. Instead, specify the ``indexes`` option - on subclasses directly, providing a unique name for each index. + (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 ``Index(fields=['title'], + name='%(app_label)s_%(class)s_title_index')``. +.. versionchanged:: 3.0 + + Interpolation of ``'%(app_label)s'`` and ``'%(class)s'`` was added. ``db_tablespace`` ----------------- -- cgit v1.3