Merge branch '404_relationship_bugfix' of git://github.com/melinath/philo
[philo.git] / models / base.py
index 23cccb6..05074c3 100644 (file)
@@ -175,11 +175,15 @@ class QuerySetMapper(object, DictMixin):
        
        def __getitem__(self, key):
                try:
        
        def __getitem__(self, key):
                try:
-                       return self.queryset.get(key__exact=key).value
+                       value = self.queryset.get(key__exact=key).value
                except ObjectDoesNotExist:
                        if self.passthrough is not None:
                                return self.passthrough.__getitem__(key)
                        raise KeyError
                except ObjectDoesNotExist:
                        if self.passthrough is not None:
                                return self.passthrough.__getitem__(key)
                        raise KeyError
+               else:
+                       if value is not None:
+                               return value.value
+                       return value
        
        def keys(self):
                keys = set(self.queryset.values_list('key', flat=True).distinct())
        
        def keys(self):
                keys = set(self.queryset.values_list('key', flat=True).distinct())
@@ -336,11 +340,5 @@ class TreeEntity(Entity, TreeModel):
                        return QuerySetMapper(self.attribute_set, passthrough=self.parent.attributes)
                return super(TreeEntity, self).attributes
        
                        return QuerySetMapper(self.attribute_set, passthrough=self.parent.attributes)
                return super(TreeEntity, self).attributes
        
-       @property
-       def relationships(self):
-               if self.parent:
-                       return QuerySetMapper(self.relationship_set, passthrough=self.parent.relationships)
-               return super(TreeEntity, self).relationships
-       
        class Meta:
                abstract = True
\ No newline at end of file
        class Meta:
                abstract = True
\ No newline at end of file