@staticmethod
    def fetch_content_instances(nodes):
        """
        Given a list of nodes, efficiently get all of their content instances.

        The structure returned looks like this::

            {
                content_type_id: {
                    content_id: content_instance,
                    content_id: content_instance,
                },
                content_type_id: {
                    content_id: content_instance,
                },
            }
        """
        # Build a mapping of content_types -> ids
        contents = defaultdict(set)
        for node in nodes:
            contents[node.content_type_id].add(node.content_id)

        # Convert that mapping to content_types -> Content instances
        for content_type_id, content_ids in contents.items():
            try:
                ct = ContentType.objects.get_for_id(content_type_id)
                model_class = ct.model_class()
            except __HOLE__:
                # get_for_id raises AttributeError when there's no model_class in django < 1.6.
                model_class = None
            if model_class:
                contents[content_type_id] = ct.model_class().objects.in_bulk(content_ids)
            else:
                ct = ContentType.objects.get(id=content_type_id)
                contents[content_type_id] = dict((id, UnknownWidget(ct, id)) for id in content_ids)
                # Warn about using an UnknownWidget. It doesn't matter which instance we use.
                next(iter(contents[content_type_id].values()), UnknownWidget(ct, None)).warn()
        return contents
dataset/ETHPy150Open fusionbox/django-widgy/widgy/models/base.py/Node.fetch_content_instances