Ticket #10074: lazy-generic-rel.diff

File lazy-generic-rel.diff, 2.0 KB (added by Alex Gaynor, 16 years ago)

I can't reproduce with the above, have I misunderstood the bug report?

  • tests/regressiontests/generic_relations_regress/models.py

    diff --git a/tests/regressiontests/generic_relations_regress/models.py b/tests/regressiontests/generic_relations_regress/models.py
    index 1a4826a..644bb98 100644
    a b class Link(models.Model):  
    1313class Place(models.Model):
    1414    name = models.CharField(max_length=100)
    1515    links = generic.GenericRelation(Link)
    16    
     16
    1717    def __unicode__(self):
    1818        return "Place: %s" % self.name
    19    
    20 class Restaurant(Place): 
     19
     20class Restaurant(Place):
    2121    def __unicode__(self):
    22         return "Restaurant: %s" % self.name
    23  No newline at end of file
     22        return "Restaurant: %s" % self.name
     23
     24class Item(models.Model):
     25    links = generic.GenericRelation('Link')
  • tests/regressiontests/generic_relations_regress/tests.py

    diff --git a/tests/regressiontests/generic_relations_regress/tests.py b/tests/regressiontests/generic_relations_regress/tests.py
    index 6f0863d..dda4288 100644
    a b  
    11from django.test import TestCase
    22from django.contrib.contenttypes.models import ContentType
    3 from models import Link, Place, Restaurant
     3from models import Link, Place, Restaurant, Item
    44
    55class GenericRelationTests(TestCase):
    6    
    76    def test_inherited_models_content_type(self):
    87        """
    98        Test that GenericRelations on inherited classes use the correct content
    109        type.
    1110        """
    12        
     11
    1312        p = Place.objects.create(name="South Park")
    14         r = Restaurant.objects.create(name="Chubby's")       
     13        r = Restaurant.objects.create(name="Chubby's")
    1514        l1 = Link.objects.create(content_object=p)
    1615        l2 = Link.objects.create(content_object=r)
    1716        self.assertEqual(list(p.links.all()), [l1])
    1817        self.assertEqual(list(r.links.all()), [l2])
    19        
    20  No newline at end of file
     18
     19    def test_lazy_generic_relation(self):
     20        p = Item.objects.create()
     21        l1 = Link()
     22        p.links.add(l1)
     23        p.delete()
Back to Top