diff options
| author | myoungjinGo-BE <myoungjingo.dev@gmail.com> | 2025-05-16 23:56:20 +0900 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-06-03 17:27:33 +0300 |
| commit | 953095d1e603fe0f8f01175b1409ca23818dcff9 (patch) | |
| tree | f10bbc6a3efa4f7d8b5eb44144f28af326dcc039 /django/contrib/contenttypes | |
| parent | 90429625a85f1f77dfea200c91bd2dabab57974f (diff) | |
Fixed #36060 -- Prevented IntegrityError in bulk_create() with order_with_respect_to.
Diffstat (limited to 'django/contrib/contenttypes')
| -rw-r--r-- | django/contrib/contenttypes/fields.py | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/django/contrib/contenttypes/fields.py b/django/contrib/contenttypes/fields.py index f9d896bc13..f28c346576 100644 --- a/django/contrib/contenttypes/fields.py +++ b/django/contrib/contenttypes/fields.py @@ -55,11 +55,15 @@ class GenericForeignKey(FieldCacheMixin, Field): attname, column = super().get_attname_column() return attname, None + @cached_property + def ct_field_attname(self): + return self.model._meta.get_field(self.ct_field).attname + def get_filter_kwargs_for_object(self, obj): """See corresponding method on Field""" return { self.fk_field: getattr(obj, self.fk_field), - self.ct_field: getattr(obj, self.ct_field), + self.ct_field_attname: getattr(obj, self.ct_field_attname), } def get_forward_related_filter(self, obj): |
