Django

Code

Changeset 8721

Show
Ignore:
Timestamp:
08/29/08 16:24:00 (3 months ago)
Author:
mtredinnick
Message:

Fixed #8279 -- Multiple many-to-many relations to "self" are now possible.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/models/fields/related.py

    r8690 r8721  
    717717        if not cls._meta.one_to_one_field: 
    718718            cls._meta.one_to_one_field = self 
    719      
     719 
    720720    def formfield(self, **kwargs): 
    721721        if self.rel.parent_link: 
     
    845845 
    846846    def contribute_to_class(self, cls, name): 
     847        # To support multiple relations to self, it's useful to have a non-None 
     848        # related name on symmetrical relations for internal reasons. The 
     849        # concept doesn't make a lot of sense externally ("you want me to 
     850        # specify *what* on my non-reversible relation?!"), so we set it up 
     851        # automatically. The funky name reduces the chance of an accidental 
     852        # clash. 
     853        if self.rel.symmetrical and self.rel.related_name is None: 
     854            self.rel.related_name = "%s_rel_+" % name 
     855 
    847856        super(ManyToManyField, self).contribute_to_class(cls, name) 
    848857        # Add the descriptor for the m2m relation