+ from philo.models import Attribute
+ ancestors = dict(self.entity.get_ancestors(include_self=True).values_list('pk', 'level'))
+ ct = ContentType.objects.get_for_model(self.entity)
+ attrs = Attribute.objects.filter(entity_content_type=ct, entity_object_id__in=ancestors.keys()).exclude(key__in=self._cache.keys())
+ return sorted(attrs, key=lambda x: ancestors[x.entity_object_id])
+
+ def _raw_get_attribute(self, key):
+ from philo.models import Attribute
+ ancestors = dict(self.entity.get_ancestors(include_self=True).values_list('pk', 'level'))
+ ct = ContentType.objects.get_for_model(self.entity)
+ try:
+ attrs = Attribute.objects.filter(entity_content_type=ct, entity_object_id__in=ancestors.keys(), key=key)
+ sorted_attrs = sorted(attrs, key=lambda x: ancestors[x.entity_object_id], reverse=True)
+ return sorted_attrs[0]
+ except IndexError:
+ raise Attribute.DoesNotExist