X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/5af34c3a3d2d9394b2e74d51fb8492ac0073ee31..dbfa7041eadc465c1aaddac3fca41624cbed852d:/models/base.py?ds=sidebyside diff --git a/models/base.py b/models/base.py index 5f8fb03..836fe4a 100644 --- a/models/base.py +++ b/models/base.py @@ -5,7 +5,7 @@ from django.contrib.contenttypes import generic 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 django.utils.encoding import force_unicode from philo.exceptions import AncestorDoesNotExist from philo.models.fields import JSONField from philo.utils import ContentTypeRegistryLimiter, ContentTypeSubclassLimiter @@ -81,10 +81,10 @@ attribute_value_limiter = ContentTypeSubclassLimiter(AttributeValue) class JSONValue(AttributeValue): - value = JSONField(verbose_name='Value (JSON)', help_text='This value must be valid JSON.', default='null') + value = JSONField(verbose_name='Value (JSON)', help_text='This value must be valid JSON.', default='null', db_index=True) def __unicode__(self): - return smart_str(self.value) + return force_unicode(self.value) def value_formfields(self): kwargs = {'initial': self.value_json} @@ -104,7 +104,7 @@ class JSONValue(AttributeValue): class ForeignKeyValue(AttributeValue): content_type = models.ForeignKey(ContentType, limit_choices_to=value_content_type_limiter, verbose_name='Value type', null=True, blank=True) - object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True) + object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True, db_index=True) value = generic.GenericForeignKey() def value_formfields(self): @@ -219,11 +219,11 @@ class ManyToManyValue(AttributeValue): class Attribute(models.Model): - entity_content_type = models.ForeignKey(ContentType, related_name='attribute_entity_set', verbose_name='Entity type', db_index=True) + entity_content_type = models.ForeignKey(ContentType, related_name='attribute_entity_set', verbose_name='Entity type') entity_object_id = models.PositiveIntegerField(verbose_name='Entity ID', db_index=True) entity = generic.GenericForeignKey('entity_content_type', 'entity_object_id') - value_content_type = models.ForeignKey(ContentType, related_name='attribute_value_set', limit_choices_to=attribute_value_limiter, verbose_name='Value type', null=True, blank=True, db_index=True) + value_content_type = models.ForeignKey(ContentType, related_name='attribute_value_set', limit_choices_to=attribute_value_limiter, verbose_name='Value type', null=True, blank=True) value_object_id = models.PositiveIntegerField(verbose_name='Value ID', null=True, blank=True, db_index=True) value = generic.GenericForeignKey('value_content_type', 'value_object_id')