diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py index d8fff50d180e..70b6590811f1 100644 --- a/django/contrib/admin/views/main.py +++ b/django/contrib/admin/views/main.py @@ -618,7 +618,7 @@ def has_related_field_in_list_display(self): else: if isinstance(field.remote_field, ManyToOneRel): # _id field names don't require a join. - if field_name != field.get_attname(): + if field_name != field.attname: return True return False diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index 3b21c742b691..770f88265c6f 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -187,7 +187,7 @@ def get_prefetch_querysets(self, instances, querysets=None): fk_dict = defaultdict(set) # We need one instance for each group in order to get the right db: instance_dict = {} - ct_attname = self.model._meta.get_field(self.ct_field).get_attname() + ct_attname = self.model._meta.get_field(self.ct_field).attname for instance in instances: # We avoid looking for values if either ct_id or fkey value is None ct_id = getattr(instance, ct_attname) @@ -240,7 +240,7 @@ def __get__(self, instance, cls=None): # content type ID here, and later when the actual instance is needed, # use ContentType.objects.get_for_id(), which has a global cache. f = self.model._meta.get_field(self.ct_field) - ct_id = getattr(instance, f.get_attname(), None) + ct_id = getattr(instance, f.attname, None) pk_val = getattr(instance, self.fk_field) rel_obj = self.get_cached_value(instance, default=None) diff --git a/django/contrib/contenttypes/forms.py b/django/contrib/contenttypes/forms.py index c0ff4f725749..741824e2fc67 100644 --- a/django/contrib/contenttypes/forms.py +++ b/django/contrib/contenttypes/forms.py @@ -67,10 +67,10 @@ def get_default_prefix(cls): def save_new(self, form, commit=True): setattr( form.instance, - self.ct_field.get_attname(), + self.ct_field.attname, ContentType.objects.get_for_model(self.instance).pk, ) - setattr(form.instance, self.ct_fk_field.get_attname(), self.instance.pk) + setattr(form.instance, self.ct_fk_field.attname, self.instance.pk) return form.save(commit=commit) diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py index 16b69770f6c3..5818bfaa84a2 100644 --- a/django/core/serializers/xml_serializer.py +++ b/django/core/serializers/xml_serializer.py @@ -106,7 +106,7 @@ def handle_fk_field(self, obj, field): differently from regular fields). """ self._start_relational_field(field) - related_att = getattr(obj, field.get_attname()) + related_att = getattr(obj, field.attname) if related_att is not None: if self.use_natural_foreign_keys and hasattr( field.remote_field.model, "natural_key" diff --git a/django/db/models/base.py b/django/db/models/base.py index c1f78d0632b5..75328e0749bb 100644 --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -1925,7 +1925,7 @@ def _check_column_name_clashes(cls): errors = [] for f in cls._meta.local_fields: - _, column_name = f.get_attname_column() + column_name = f.column # Ensure the column name is not already in use. if column_name and column_name in used_column_names: @@ -1972,7 +1972,7 @@ def _check_property_name_related_field_accessor_clashes(cls): errors = [] property_names = cls._meta._property_names related_field_accessors = ( - f.get_attname() + f.attname for f in cls._meta._get_fields(reverse=False) if f.is_relation and f.related_model is not None ) @@ -2320,13 +2320,11 @@ def _check_long_column_names(cls, databases): return errors for f in cls._meta.local_fields: - _, column_name = f.get_attname_column() - # Check if auto-generated name for the field is too long # for the database. if ( f.db_column is None - and column_name is not None + and (column_name := f.column) is not None and len(column_name) > allowed_len ): errors.append( @@ -2348,10 +2346,9 @@ def _check_long_column_names(cls, databases): # Check if auto-generated name for the M2M field is too long # for the database. for m2m in f.remote_field.through._meta.local_fields: - _, rel_name = m2m.get_attname_column() if ( m2m.db_column is None - and rel_name is not None + and (rel_name := m2m.column) is not None and len(rel_name) > allowed_len ): errors.append( diff --git a/django/db/models/expressions.py b/django/db/models/expressions.py index 6d329ae85d38..e59dfbe2492f 100644 --- a/django/db/models/expressions.py +++ b/django/db/models/expressions.py @@ -1204,8 +1204,7 @@ def resolve_expression( if query.model: for parent in query.model._meta.get_parent_list(): for parent_field in parent._meta.local_fields: - _, column_name = parent_field.get_attname_column() - if column_name.lower() in self.sql.lower(): + if parent_field.column.lower() in self.sql.lower(): query.resolve_ref( parent_field.name, allow_joins, reuse, summarize ) diff --git a/django/db/models/query.py b/django/db/models/query.py index b9e2d1f7e510..94819758dd65 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -2186,8 +2186,7 @@ def model_fields(self): converter = connections[self.db].introspection.identifier_converter model_fields = {} for field in self.model._meta.fields: - name, column = field.get_attname_column() - model_fields[converter(column)] = field + model_fields[converter(field.column)] = field return model_fields diff --git a/django/forms/models.py b/django/forms/models.py index cd6986d72a79..4b11d5af8c16 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -1140,7 +1140,7 @@ def _construct_form(self, i, **kwargs): if self.fk.remote_field.field_name != self.fk.remote_field.model._meta.pk.name: fk_value = getattr(self.instance, self.fk.remote_field.field_name) fk_value = getattr(fk_value, "pk", fk_value) - setattr(form.instance, self.fk.get_attname(), fk_value) + setattr(form.instance, self.fk.attname, fk_value) return form @classmethod