diff options
| author | Adam Johnson <me@adamj.eu> | 2024-03-07 04:59:13 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-07 05:59:13 +0100 |
| commit | 9e35c8b2e37ab228b169e63a71f7221e4e85f3da (patch) | |
| tree | 30188b892aa3517a490cae6b7081bbf4a99f3998 /django/db/models/options.py | |
| parent | c4df2a77761a1ae392eb5c4803b5712803d5239f (diff) | |
Refs #30397 -- Optimized interpolation of index and constraint names a bit.
Diffstat (limited to 'django/db/models/options.py')
| -rw-r--r-- | django/db/models/options.py | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/django/db/models/options.py b/django/db/models/options.py index 7e2896a6a2..7a6fdc413e 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -203,10 +203,9 @@ class Options: self.unique_together = normalize_together(self.unique_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)) + if not self.abstract: + self.constraints = self._format_names_with_class(cls, self.constraints) + self.indexes = self._format_names_with_class(cls, self.indexes) # verbose_name_plural is a special case because it uses a 's' # by default. @@ -234,13 +233,14 @@ class Options: def _format_names_with_class(self, cls, objs): """App label/class name interpolation for object names.""" + names = { + "app_label": cls._meta.app_label.lower(), + "class": cls.__name__.lower(), + } new_objs = [] for obj in objs: obj = obj.clone() - obj.name = obj.name % { - "app_label": cls._meta.app_label.lower(), - "class": cls.__name__.lower(), - } + obj.name = obj.name % names new_objs.append(obj) return new_objs |
