Ticket #12721: 12721_r12344.diff

File 12721_r12344.diff, 3.4 KB (added by Carl Meyer, 15 years ago)
  • django/db/models/sql/subqueries.py

    diff --git a/django/db/models/sql/subqueries.py b/django/db/models/sql/subqueries.py
    a b  
    5050
    5151        for f in cls._meta.many_to_many:
    5252            w1 = self.where_class()
     53            db_prep_value = None
    5354            if isinstance(f, generic.GenericRelation):
    5455                from django.contrib.contenttypes.models import ContentType
    55                 field = f.rel.to._meta.get_field(f.content_type_field_name)
    56                 w1.add((Constraint(None, field.column, field), 'exact',
     56                ct_field = f.rel.to._meta.get_field(f.content_type_field_name)
     57                w1.add((Constraint(None, ct_field.column, ct_field), 'exact',
    5758                        ContentType.objects.get_for_model(cls).id), AND)
     59                id_field = f.rel.to._meta.get_field(f.object_id_field_name)
     60                db_prep_value = id_field.get_db_prep_value
    5861            for offset in range(0, len(pk_list), GET_ITERATOR_CHUNK_SIZE):
    5962                where = self.where_class()
    6063                where.add((Constraint(None, f.m2m_column_name(), f), 'in',
    61                         pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE]),
     64                        map(db_prep_value,
     65                            pk_list[offset : offset + GET_ITERATOR_CHUNK_SIZE])),
    6266                        AND)
    6367                if w1:
    6468                    where.add(w1, AND)
  • 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
    a b  
    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
  • 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
    a b  
    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()
Back to Top