From 1669e54965e22d9bfd0cc8f8fb969704ac608163 Mon Sep 17 00:00:00 2001 From: Nick Pope Date: Fri, 8 Mar 2024 04:49:32 +0000 Subject: [PATCH] Refs #30397 -- Optimized interpolation of index and constraint names a bit more. --- django/db/models/options.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/django/db/models/options.py b/django/db/models/options.py index 7a6fdc413e..6f08feec25 100644 --- a/django/db/models/options.py +++ b/django/db/models/options.py @@ -204,8 +204,8 @@ class Options: # App label/class name interpolation for names of constraints and # indexes. if not self.abstract: - self.constraints = self._format_names_with_class(cls, self.constraints) - self.indexes = self._format_names_with_class(cls, self.indexes) + self.constraints = self._format_names(self.constraints) + self.indexes = self._format_names(self.indexes) # verbose_name_plural is a special case because it uses a 's' # by default. @@ -231,16 +231,13 @@ class Options: self.db_table, connection.ops.max_name_length() ) - def _format_names_with_class(self, cls, objs): + def _format_names(self, objs): """App label/class name interpolation for object names.""" - names = { - "app_label": cls._meta.app_label.lower(), - "class": cls.__name__.lower(), - } + names = {"app_label": self.app_label.lower(), "class": self.model_name} new_objs = [] for obj in objs: obj = obj.clone() - obj.name = obj.name % names + obj.name %= names new_objs.append(obj) return new_objs