Ticket #12721: oddrel.diff

File oddrel.diff, 2.1 KB (added by Karen Tracey, 15 years ago)
  • tests/regressiontests/generic_relations_regress/tests.py

     
    11from django.test import TestCase
    22from django.contrib.contenttypes.models import ContentType
    3 from models import Link, Place, Restaurant, Person, Address
     3from models import Link, Place, Restaurant, Person, Address, CharLink, TextLink, OddRelation1, OddRelation2
    44
    55class GenericRelationTests(TestCase):
    66
     
    3030        qs = Person.objects.filter(addresses__zipcode='80433')
    3131        self.assertEqual(1, qs.count())
    3232        self.assertEqual('Chef', qs[0].name)
     33
     34    def test_charlink_delete(self):
     35        oddrel = OddRelation1.objects.create(name='clink')
     36        cl = CharLink.objects.create(content_object=oddrel)
     37        oddrel.delete()
     38
     39    def test_textlink_delete(self):
     40        oddrel = OddRelation2.objects.create(name='tlink')
     41        tl = TextLink.objects.create(content_object=oddrel)
     42        oddrel.delete()
  • tests/regressiontests/generic_relations_regress/models.py

     
    4040
    4141    def __unicode__(self):
    4242        return self.name
     43
     44class CharLink(models.Model):
     45    content_type = models.ForeignKey(ContentType)
     46    object_id = models.CharField(max_length=100)
     47    content_object = generic.GenericForeignKey()
     48
     49class TextLink(models.Model):
     50    content_type = models.ForeignKey(ContentType)
     51    object_id = models.TextField()
     52    content_object = generic.GenericForeignKey()
     53
     54class OddRelation1(models.Model):
     55    name = models.CharField(max_length=100)
     56    clinks = generic.GenericRelation(CharLink)
     57
     58class OddRelation2(models.Model):
     59    name = models.CharField(max_length=100)
     60    tlinks = generic.GenericRelation(TextLink)
     61
Back to Top