diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-29 21:24:00 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2008-08-29 21:24:00 +0000 |
| commit | f04123f4dfbbf862e397b6e8c7a96aa5cd39ac1d (patch) | |
| tree | 8cc20e32b74feaf231f5df1cfb83d725053d287c /django | |
| parent | ae953a8c4e87172a3dfd37df3f5f6890ce9b00a7 (diff) | |
Fixed #8279 -- Multiple many-to-many relations to "self" are now possible.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8721 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/models/fields/related.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py index bd453e53b1..369674563a 100644 --- a/django/db/models/fields/related.py +++ b/django/db/models/fields/related.py @@ -716,7 +716,7 @@ class OneToOneField(ForeignKey): SingleRelatedObjectDescriptor(related)) if not cls._meta.one_to_one_field: cls._meta.one_to_one_field = self - + def formfield(self, **kwargs): if self.rel.parent_link: return None @@ -844,6 +844,15 @@ class ManyToManyField(RelatedField, Field): return smart_unicode(data) def contribute_to_class(self, cls, name): + # To support multiple relations to self, it's useful to have a non-None + # related name on symmetrical relations for internal reasons. The + # concept doesn't make a lot of sense externally ("you want me to + # specify *what* on my non-reversible relation?!"), so we set it up + # automatically. The funky name reduces the chance of an accidental + # clash. + if self.rel.symmetrical and self.rel.related_name is None: + self.rel.related_name = "%s_rel_+" % name + super(ManyToManyField, self).contribute_to_class(cls, name) # Add the descriptor for the m2m relation setattr(cls, self.name, ReverseManyRelatedObjectsDescriptor(self)) |
