X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/ee93c1aed3616a880050bed082bcc0636d4ed92b..4d7f6c42629cb85f001306195c6098b4abec642a:/models/base.py diff --git a/models/base.py b/models/base.py index 34e90dc..fae385a 100644 --- a/models/base.py +++ b/models/base.py @@ -2,8 +2,9 @@ from django import forms from django.db import models from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes import generic -from django.utils import simplejson as json from django.core.exceptions import ObjectDoesNotExist +from django.utils import simplejson as json +from django.utils.encoding import smart_str from philo.exceptions import AncestorDoesNotExist from philo.models.fields import JSONField from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter @@ -73,7 +74,7 @@ class JSONValue(AttributeValue): value = JSONField() #verbose_name='Value (JSON)', help_text='This value must be valid JSON.') def __unicode__(self): - return self.value_json + return smart_str(self.value) def value_formfield(self, **kwargs): kwargs['initial'] = self.value_json @@ -358,7 +359,7 @@ class TreeManager(models.Manager): if deepest_level == depth: # This should happen if nothing is found with any part of the given path. - if root is not None: + if root is not None and deepest_found is None: return root, build_path(segments) raise @@ -413,7 +414,7 @@ class TreeModel(MPTTModel): qs = self.get_ancestors() if root is not None: - qs = qs.filter(level__gt=root.level) + qs = qs.filter(**{'%s__gt' % self._mptt_meta.level_attr: root.get_level()}) return pathsep.join([getattr(parent, field, '?') for parent in list(qs) + [self]]) path = property(get_path)