X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/0adc7822400fb7fa49bc15a13e3e74e997184e80..16c91c1902f065c6d9b12a5c89c04d6aef620291:/models/fields.py diff --git a/models/fields.py b/models/fields.py index 19a6006..83798c4 100644 --- a/models/fields.py +++ b/models/fields.py @@ -243,6 +243,11 @@ class JSONField(models.TextField): def contribute_to_class(self, cls, name): super(JSONField, self).contribute_to_class(cls, name) setattr(cls, name, JSONDescriptor(self)) + models.signals.pre_init.connect(self.fix_init_kwarg, sender=cls) + + def fix_init_kwarg(self, sender, args, kwargs, **signal_kwargs): + if self.name in kwargs: + kwargs[self.attname] = json.dumps(kwargs.pop(self.name)) def formfield(self, *args, **kwargs): kwargs["form_class"] = JSONFormField