diff options
| author | can <cansarigol@derinbilgi.com.tr> | 2019-07-05 15:15:41 +0300 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-07-08 14:57:56 +0200 |
| commit | febe136d4c3310ec8901abecca3ea5ba2be3952c (patch) | |
| tree | 4eeae36c3ae832a90f8a4721b2de54ea555a8478 /django | |
| parent | 8233144ca0c93b589b61a2ad0fb7c851f3356a3b (diff) | |
Fixed #30397 -- Added app_label/class interpolation for names of indexes and constraints.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/options.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index fea65f7626..1f11e26d87 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -180,6 +180,12 @@ class Options: self.unique_together = normalize_together(self.unique_together) self.index_together = normalize_together(self.index_together) + # App label/class name interpolation for names of constraints and + # indexes. + if not getattr(cls._meta, 'abstract', False): + for attr_name in {'constraints', 'indexes'}: + objs = getattr(self, attr_name, []) + setattr(self, attr_name, self._format_names_with_class(cls, objs)) # verbose_name_plural is a special case because it uses a 's' # by default. @@ -201,6 +207,18 @@ class Options: self.db_table = "%s_%s" % (self.app_label, self.model_name) self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) + def _format_names_with_class(self, cls, objs): + """App label/class name interpolation for object names.""" + new_objs = [] + for obj in objs: + obj = obj.clone() + obj.name = obj.name % { + 'app_label': cls._meta.app_label.lower(), + 'class': cls.__name__.lower(), + } + new_objs.append(obj) + return new_objs + def _prepare(self, model): if self.order_with_respect_to: # The app registry will not be ready at this point, so we cannot |
