Skip to content

Instantly share code, notes, and snippets.

@loic
Last active December 27, 2015 20:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loic/7382392 to your computer and use it in GitHub Desktop.
Save loic/7382392 to your computer and use it in GitHub Desktop.
diff --git a/django/db/models/fields/related.py b/django/db/models/fields/related.py
index 6299b20..577f503 100644
--- a/django/db/models/fields/related.py
+++ b/django/db/models/fields/related.py
@@ -268,7 +268,7 @@ class ReverseSingleRelatedObjectDescriptor(six.with_metaclass(RenameRelatedObjec
rel_obj_attr = self.field.get_foreign_related_value
instance_attr = self.field.get_local_related_value
instances_dict = dict((instance_attr(inst), inst) for inst in instances)
- query = {'%s__in' % self.field.related_query_name(): instances}
+ query = {'%s__in' % self.field.related_field.name: set([instance_attr(i)[0] for i in instances])}
qs = self.get_queryset(instance=instances[0]).filter(**query)
# Since we're going to assign directly in the cache,
# we must manage the reverse relation cache manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment