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

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7561 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2008-05-29 12:17:03 +00:00
parent 812d8d40bd
commit 5837a45bd9
2 changed files with 17 additions and 1 deletions

View File

@ -165,7 +165,7 @@ class SingleRelatedObjectDescriptor(object):
# SingleRelatedObjectDescriptor instance.
def __init__(self, related):
self.related = related
self.cache_name = '_%s_cache' % related.field.name
self.cache_name = '_%s_cache' % related.get_accessor_name()
def __get__(self, instance, instance_type=None):
if instance is None:

View File

@ -15,6 +15,13 @@ class Restaurant(models.Model):
def __unicode__(self):
return u"%s the restaurant" % self.place.name
class Bar(models.Model):
place = models.OneToOneField(Place)
serves_cocktails = models.BooleanField()
def __unicode__(self):
return u"%s the bar" % self.place.name
class Favorites(models.Model):
name = models.CharField(max_length = 50)
restaurants = models.ManyToManyField(Restaurant)
@ -34,4 +41,13 @@ __test__ = {'API_TESTS':"""
>>> f.restaurants = [r]
>>> f.restaurants.all()
[<Restaurant: Demon Dogs the restaurant>]
# Regression test for #7173: Check that the name of the cache for the
# reverse object is correct.
>>> b = Bar(place=p1, serves_cocktails=False)
>>> b.save()
>>> p1.restaurant
<Restaurant: Demon Dogs the restaurant>
>>> p1.bar
<Bar: Demon Dogs the bar>
"""}