Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed field.rel.field_name handling

This is a regression fix to multicolumn joins. Refs #19385.
  • Loading branch information...
commit 0e0eb8a9553bb89347ceb159537ccc417cb5e7f5 1 parent 014638a
@akaariai akaariai authored
Showing with 14 additions and 0 deletions.
  1. +14 −0 django/db/models/fields/related.py
View
14 django/db/models/fields/related.py
@@ -126,6 +126,7 @@ def set_attributes_from_rel(self):
self.name = self.name or (self.rel.to._meta.model_name + '_' + self.rel.to._meta.pk.name)
if self.verbose_name is None:
self.verbose_name = self.rel.to._meta.verbose_name
+ self.rel.set_field_name()
def do_related_class(self, other, cls):
self.set_attributes_from_rel()
@@ -863,6 +864,16 @@ def get_joining_columns(self):
def get_extra_restriction(self, where_class, alias, related_alias):
return self.field.get_extra_restriction(where_class, related_alias, alias)
+ def set_field_name(self):
+ """
+ Sets the related field's name, this is not available until later stages
+ of app loading, so set_field_name is called from
+ set_attributes_from_rel()
+ """
+ # By default foreign object doesn't relate to any remote field (for
+ # example custom multicolumn joins currently have no remote field).
+ self.field_name = None
+
class ManyToOneRel(ForeignObjectRel):
def __init__(self, field, to, field_name, related_name=None, limit_choices_to=None,
parent_link=False, on_delete=None):
@@ -882,6 +893,9 @@ def get_related_field(self):
self.field_name)
return data[0]
+ def set_field_name(self):
+ self.field_name = self.field_name or self.to._meta.pk.name
+
class OneToOneRel(ManyToOneRel):
def __init__(self, field, to, field_name, related_name=None, limit_choices_to=None,
Please sign in to comment.
Something went wrong with that request. Please try again.