from django.db import models class GFKManager(models.Manager): def relate(self, qs): model_map = {} item_map = {} for item in qs: model_map.setdefault(item.content_type, {}) \ [item.object_id] = item.id item_map[item.id] = item for ct, items_ in model_map.items(): for o in ct.model_class().objects.select_related() \ .filter(id__in=items_.keys()).all(): item_map[items_[o.id]].content_object = o return qs