Author: mtredinnick
Date: 2009-04-04 00:35:01 -0500 (Sat, 04 Apr 2009)
New Revision: 10384

Modified:
   django/trunk/django/db/models/sql/query.py
   django/trunk/tests/regressiontests/defer_regress/models.py
Log:
Fixed a problem when computing deferred fields on multiple related models.

Fixed #10710, as this fixes the second bug reported there.

Modified: django/trunk/django/db/models/sql/query.py
===================================================================
--- django/trunk/django/db/models/sql/query.py  2009-04-04 05:34:23 UTC (rev 
10383)
+++ django/trunk/django/db/models/sql/query.py  2009-04-04 05:35:01 UTC (rev 
10384)
@@ -574,12 +574,13 @@
         if not field_names:
             return
         columns = set()
-        cur_model = self.model
-        opts = cur_model._meta
+        orig_opts = self.model._meta
         seen = {}
-        must_include = {cur_model: set([opts.pk])}
+        must_include = {self.model: set([orig_opts.pk])}
         for field_name in field_names:
             parts = field_name.split(LOOKUP_SEP)
+            cur_model = self.model
+            opts = orig_opts
             for name in parts[:-1]:
                 old_model = cur_model
                 source = opts.get_field_by_name(name)[0]

Modified: django/trunk/tests/regressiontests/defer_regress/models.py
===================================================================
--- django/trunk/tests/regressiontests/defer_regress/models.py  2009-04-04 
05:34:23 UTC (rev 10383)
+++ django/trunk/tests/regressiontests/defer_regress/models.py  2009-04-04 
05:35:01 UTC (rev 10384)
@@ -24,6 +24,7 @@
 class Leaf(models.Model):
     name = models.CharField(max_length=10)
     child = models.ForeignKey(Child)
+    second_child = models.ForeignKey(Child, related_name="other", null=True)
     value = models.IntegerField(default=42)
 
     def __unicode__(self):
@@ -87,6 +88,8 @@
 >>> obj = Leaf.objects.only("name", "child").select_related()[0]
 >>> obj.child.name
 u'c1'
+>>> Leaf.objects.select_related().only("child__name", "second_child__name")
+[<Leaf_Deferred_name_value: l1>]
 
 """
 }


--~--~---------~--~----~------------~-------~--~----~
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