X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/e095f691f243784f8c8d0a9773270b9dbead18e9..16c91c1902f065c6d9b12a5c89c04d6aef620291:/models/base.py?ds=inline diff --git a/models/base.py b/models/base.py index c7b1c26..8140520 100644 --- a/models/base.py +++ b/models/base.py @@ -2,8 +2,10 @@ 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.core.validators import RegexValidator +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 @@ -22,6 +24,7 @@ class Tag(models.Model): class Meta: app_label = 'philo' + ordering = ('name',) class Titled(models.Model): @@ -73,7 +76,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 @@ -178,7 +181,7 @@ class Attribute(models.Model): value_object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True) value = generic.GenericForeignKey('value_content_type', 'value_object_id') - key = models.CharField(max_length=255) + key = models.CharField(max_length=255, validators=[RegexValidator("\w+")], help_text="Must contain one or more alphanumeric characters or underscores.") def __unicode__(self): return u'"%s": %s' % (self.key, self.value)