Django

Code

Changeset 7764

Show
Ignore:
Timestamp:
06/26/08 05:50:25 (2 months ago)
Author:
mtredinnick
Message:

Fixed the way symmetrical many-to-many relations are recorded in the Options class.

These types of relations don't have reverse accessor names, so that name can be
used by a normal field on the model. Fixed #7107.

Files:

Legend:

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

    r7600 r7764  
    275275        Initialises the field name -> field object mapping. 
    276276        """ 
    277         cache = dict([(f.name, (f, m, True, False)) for f, m in 
    278                 self.get_fields_with_model()]) 
    279         for f, model in self.get_m2m_with_model(): 
    280             cache[f.name] = (f, model, True, True) 
     277        cache = {} 
     278        # We intentionally handle related m2m objects first so that symmetrical 
     279        # m2m accessor names can be overridden, if necessary. 
    281280        for f, model in self.get_all_related_m2m_objects_with_model(): 
    282281            cache[f.field.related_query_name()] = (f, model, False, True) 
    283282        for f, model in self.get_all_related_objects_with_model(): 
    284283            cache[f.field.related_query_name()] = (f, model, False, False) 
     284        for f, model in self.get_m2m_with_model(): 
     285            cache[f.name] = (f, model, True, True) 
     286        for f, model in self.get_fields_with_model(): 
     287            cache[f.name] = (f, model, True, False) 
    285288        if self.order_with_respect_to: 
    286289            cache['_order'] = OrderWrt(), None, True, False 
  • django/trunk/tests/regressiontests/queries/models.py

    r7761 r7764  
    9090    def __unicode__(self): 
    9191        return unicode(self.num) 
     92 
     93# Symmetrical m2m field with a normal field using the reverse accesor name 
     94# ("valid"). 
     95class Valid(models.Model): 
     96    valid = models.CharField(max_length=10) 
     97    parent = models.ManyToManyField('self') 
     98 
     99    class Meta: 
     100        ordering = ['valid'] 
    92101 
    93102# Some funky cross-linked models for testing a couple of infinite recursion 
     
    7697785 
    770779 
     780Bug #7107 -- this shouldn't create an infinite loop. 
     781>>> Valid.objects.all() 
     782[] 
     783 
    771784"""} 
    772785