Created
August 4, 2010 13:01
-
-
Save dickbrouwer/508100 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qs = MyRelatedObject.objects.all() | |
obj_dict = dict([(obj.id, obj) for obj in qs]) | |
objects = MyObject.objects.filter(myrelatedobj__in=qs) | |
relation_dict = {} | |
for obj in objects: | |
relation_dict.setdefault(obj.myobject_id, []).append(obj) | |
for id, related_items in relation_dict.items(): | |
obj_dict[id].related_items = related_items |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment