Django

Code

Changeset 7561

Show
Ignore:
Timestamp:
05/29/08 07:17:03 (4 months ago)
Author:
russellm
Message:

Fixed #7173 -- Corrected the caching of objects in reverse OneToOne? relationships. Thanks, Travis Terry.

Files:

Legend:

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

    r7556 r7561  
    166166    def __init__(self, related): 
    167167        self.related = related 
    168         self.cache_name = '_%s_cache' % related.field.name 
     168        self.cache_name = '_%s_cache' % related.get_accessor_name() 
    169169 
    170170    def __get__(self, instance, instance_type=None): 
  • django/trunk/tests/regressiontests/one_to_one_regress/models.py

    r5876 r7561  
    1515    def __unicode__(self): 
    1616        return u"%s the restaurant" % self.place.name 
     17 
     18class Bar(models.Model): 
     19    place = models.OneToOneField(Place) 
     20    serves_cocktails = models.BooleanField() 
     21 
     22    def __unicode__(self): 
     23        return u"%s the bar" % self.place.name 
    1724 
    1825class Favorites(models.Model): 
     
    3542>>> f.restaurants.all() 
    3643[<Restaurant: Demon Dogs the restaurant>] 
     44 
     45# Regression test for #7173: Check that the name of the cache for the  
     46# reverse object is correct. 
     47>>> b = Bar(place=p1, serves_cocktails=False) 
     48>>> b.save() 
     49>>> p1.restaurant 
     50<Restaurant: Demon Dogs the restaurant> 
     51>>> p1.bar 
     52<Bar: Demon Dogs the bar> 
    3753"""}