<s> from django . contrib . contenttypes . models import ContentType <EOL> def fetch_content_objects ( tagged_items , select_related_for = None ) : <EOL> """<STR_LIT>""" <EOL> if select_related_for is None : <EOL> select_related_for = [ ] <EOL> objects = { } <EOL> for item in tagged_items : <EOL> objects . setdefault ( item . content_type_id , [ ] ) . append ( item . object_id ) <EOL> content_types = ContentType . _default_manager . in_bulk ( objects . keys ( ) ) <EOL> for content_type_pk , object_pks in objects . iteritems ( ) : <EOL> model = content_types [ content_type_pk ] . model_class ( ) <EOL> if content_types [ content_type_pk ] . model in select_related_for : <EOL> objects [ content_type_pk ] = model . _default_manager . select_related ( ) . in_bulk ( object_pks ) <EOL> else : <EOL> objects [ content_type_pk ] = model . _default_manager . in_bulk ( object_pks ) <EOL> for item in tagged_items : <EOL> item . _object_cache = objects [ item . content_type_id ] [ item . object_id ] <EOL> item . _content_type_cache = content_types [ item . content_type_id ] </s>
