Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #7173 -- Corrected the caching of objects in reverse OneToOne r…

…elationships. Thanks, Travis Terry.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@7561 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 5837a45bd94ac06c7e2036b89701e579a2fe9faf 1 parent 812d8d4
@freakboy3742 freakboy3742 authored
View
2  django/db/models/fields/related.py
@@ -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
16 tests/regressiontests/one_to_one_regress/models.py
@@ -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 @@ def __unicode__(self):
>>> 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>
"""}
Please sign in to comment.
Something went wrong with that request. Please try again.