'Regression test for #6886 (the related-object cache)'

def test_related_object_cache(self):

    p = Place.objects.get(name='Demon    Dogs')
    r = p.restaurant
    self.assertIs(p.restaurant, r)
    del p._restaurant_cache
    self.assertIsNot(p.restaurant, r)
    r2 = Restaurant.objects.get(pk=r.pk)
    p.restaurant = r2
    self.assertIs(p.restaurant, r2)
    ug_bar = UndergroundBar.objects.create(place=p, serves_cocktails=False)
    ug_bar.place = None
    self.assertIsNone(ug_bar.place)
    setattr(p, 'restaurant', None)
    msg = 'Cannot    assign    "<Place:    Demon    Dogs    the    place>":    "Place.restaurant"    must    be    a    "Restaurant"    instance.'
    with self.assertRaisesMessage(ValueError, msg):
        setattr(p, 'restaurant', p)
    p = Place.objects.get(name='Demon    Dogs')
    r = Restaurant(place=p)
    self.assertIs(r.place, p)
    p = Place()
    r = Restaurant(place=p)
    self.assertTrue((r.place is p))
    p = Place.objects.get(name='Demon    Dogs')
    r = Restaurant(place_id=p.id)
    self.assertIsNot(r.place, p)
    self.assertEqual(r.place, p)
