X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/e0de41ae1e67c230ad1e67f34f6f4f76e53d7234..a6f352b9bd87c171ee870cdb1fe9728596cd7ff8:/apps/sponsors/fields.py diff --git a/apps/sponsors/fields.py b/apps/sponsors/fields.py index 26effc541..ba980816f 100644 --- a/apps/sponsors/fields.py +++ b/apps/sponsors/fields.py @@ -8,6 +8,7 @@ from django.conf import settings from django.db import models from django import forms from django.utils import simplejson as json +from south.modelsinspector import add_introspection_rules class JSONEncoder(json.JSONEncoder): @@ -31,7 +32,7 @@ def loads(str): class JSONFormField(forms.CharField): widget = forms.Textarea - + def clean(self, value): try: loads(value) @@ -46,7 +47,7 @@ class JSONField(models.TextField): defaults.update(kwargs) return super(JSONField, self).formfield(**defaults) - def db_type(self): + def db_type(self, connection): return 'text' def get_internal_type(self): @@ -54,7 +55,7 @@ class JSONField(models.TextField): def contribute_to_class(self, cls, name): super(JSONField, self).contribute_to_class(cls, name) - + def get_value(model_instance): return loads(getattr(model_instance, self.attname, None)) setattr(cls, 'get_%s_value' % self.name, get_value) @@ -62,3 +63,5 @@ class JSONField(models.TextField): def set_value(model_instance, json): return setattr(model_instance, self.attname, dumps(json)) setattr(cls, 'set_%s_value' % self.name, set_value) + +add_introspection_rules([], [r"^sponsors\.fields\.JSONField"])