X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/ad793ef31605b952b80fb2c1be968b5d8973344b..156ac8bc47f9ff52ff92610ae05c589b31d609e0:/philo/utils/entities.py?ds=inline diff --git a/philo/utils/entities.py b/philo/utils/entities.py index 1ddff05..c7b14b7 100644 --- a/philo/utils/entities.py +++ b/philo/utils/entities.py @@ -1,8 +1,11 @@ +from functools import partial from UserDict import DictMixin from django.db import models from django.contrib.contenttypes.models import ContentType +from philo.utils.lazycompat import SimpleLazyObject + ### AttributeMappers @@ -83,15 +86,19 @@ class AttributeMapper(object, DictMixin): value_lookups = {} for a in attributes: - value_lookups.setdefault(a.value_content_type, []).append(a.value_object_id) + value_lookups.setdefault(a.value_content_type_id, []).append(a.value_object_id) self._attributes_cache[a.key] = a values_bulk = {} - for ct, pks in value_lookups.items(): - values_bulk[ct] = ct.model_class().objects.in_bulk(pks) + for ct_pk, pks in value_lookups.items(): + values_bulk[ct_pk] = ContentType.objects.get_for_id(ct_pk).model_class().objects.in_bulk(pks) - self._cache.update(dict([(a.key, getattr(values_bulk[a.value_content_type].get(a.value_object_id), 'value', None)) for a in attributes])) + self._cache.update(dict([ + ( + a.key, + SimpleLazyObject(partial(getattr, values_bulk[a.value_content_type_id].get(a.value_object_id), 'value', None)) + ) for a in attributes])) self._cache_filled = True def clear_cache(self):