summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-11-28 23:52:50 +0200
committerAnssi Kääriäinen <akaariai@gmail.com>2012-11-28 23:56:03 +0200
commite3ea668b47f6b7d63abd93a62b89f809cd3d5146 (patch)
tree0b8a49c02534d5bacbb84bf89bf931bbf1c09576
parent957de74ebe8219b97f628a21004ca83833146713 (diff)
[1.5.x] Fixed #14694 again -- Made defer() works with reverse relations
Master and stable/1.5.x had diverged in models/query.py.
-rw-r--r--django/db/models/query.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 67fef52f36..9d0fbc02dc 100644
--- a/django/db/models/query.py
+++ b/django/db/models/query.py
@@ -1478,9 +1478,14 @@ def get_cached_row(row, index_start, using, klass_info, offset=0):
# If the related object exists, populate
# the descriptor cache.
setattr(rel_obj, f.get_cache_name(), obj)
- # Now populate all the non-local field values
- # on the related object
- for rel_field, rel_model in rel_obj._meta.get_fields_with_model():
+ # Now populate all the non-local field values on the related
+ # object. If this object has deferred fields, we need to use
+ # the opts from the original model to get non-local fields
+ # correctly.
+ opts = rel_obj._meta
+ if getattr(rel_obj, '_deferred'):
+ opts = opts.proxy_for_model._meta
+ for rel_field, rel_model in opts.get_fields_with_model():
if rel_model is not None:
setattr(rel_obj, rel_field.attname, getattr(obj, rel_field.attname))
# populate the field cache for any related object