Author: jacob
Date: 2009-04-03 14:56:30 -0500 (Fri, 03 Apr 2009)
New Revision: 10374

Added:
   
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/
   
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/__init__.py
   
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/models.py
   
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/tests.py
Modified:
   django/branches/releases/1.0.X/django/contrib/contenttypes/generic.py
Log:
[1.0.X] Fixed #9546: GenericRelations inherited from base models no longer 
query using the wrong content type. Backport of r10373 from trunk.

Modified: django/branches/releases/1.0.X/django/contrib/contenttypes/generic.py
===================================================================
--- django/branches/releases/1.0.X/django/contrib/contenttypes/generic.py       
2009-04-03 19:52:14 UTC (rev 10373)
+++ django/branches/releases/1.0.X/django/contrib/contenttypes/generic.py       
2009-04-03 19:56:30 UTC (rev 10374)
@@ -193,9 +193,9 @@
         rel_model = self.field.rel.to
         superclass = rel_model._default_manager.__class__
         RelatedManager = create_generic_related_manager(superclass)
-
+        
         qn = connection.ops.quote_name
-
+                
         manager = RelatedManager(
             model = rel_model,
             instance = instance,
@@ -203,7 +203,7 @@
             join_table = qn(self.field.m2m_db_table()),
             source_col_name = qn(self.field.m2m_column_name()),
             target_col_name = qn(self.field.m2m_reverse_name()),
-            content_type = ContentType.objects.get_for_model(self.field.model),
+            content_type = ContentType.objects.get_for_model(instance),
             content_type_field_name = self.field.content_type_field_name,
             object_id_field_name = self.field.object_id_field_name
         )

Added: 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/__init__.py
===================================================================

Added: 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/models.py
===================================================================
--- 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/models.py
                            (rev 0)
+++ 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/models.py
    2009-04-03 19:56:30 UTC (rev 10374)
@@ -0,0 +1,22 @@
+from django.db import models
+from django.contrib.contenttypes import generic
+from django.contrib.contenttypes.models import ContentType
+
+class Link(models.Model):
+    content_type = models.ForeignKey(ContentType)
+    object_id = models.PositiveIntegerField()
+    content_object = generic.GenericForeignKey()
+
+    def __unicode__(self):
+        return "Link to %s id=%s" % (self.content_type, self.object_id)
+
+class Place(models.Model):
+    name = models.CharField(max_length=100)
+    links = generic.GenericRelation(Link)
+    
+    def __unicode__(self):
+        return "Place: %s" % self.name
+    
+class Restaurant(Place): 
+    def __unicode__(self):
+        return "Restaurant: %s" % self.name
\ No newline at end of file

Added: 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/tests.py
===================================================================
--- 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/tests.py
                             (rev 0)
+++ 
django/branches/releases/1.0.X/tests/regressiontests/generic_relations_regress/tests.py
     2009-04-03 19:56:30 UTC (rev 10374)
@@ -0,0 +1,19 @@
+from django.test import TestCase
+from django.contrib.contenttypes.models import ContentType
+from models import Link, Place, Restaurant
+
+class GenericRelationTests(TestCase):
+    
+    def test_inherited_models_content_type(self):
+        """
+        Test that GenericRelations on inherited classes use the correct content
+        type.
+        """
+        
+        p = Place.objects.create(name="South Park")
+        r = Restaurant.objects.create(name="Chubby's")        
+        l1 = Link.objects.create(content_object=p)
+        l2 = Link.objects.create(content_object=r)
+        self.assertEqual(list(p.links.all()), [l1])
+        self.assertEqual(list(r.links.all()), [l2])
+        
\ No newline at end of file


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to