X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/faa929ce6af603e83247f3f5f8c6f6c22aff48bc..b3fd01202e71b1a43ab372b8f19e9ff6f13dae7b:/models/fields/__init__.py?ds=inline diff --git a/models/fields/__init__.py b/models/fields/__init__.py index 25af832..d900e31 100644 --- a/models/fields/__init__.py +++ b/models/fields/__init__.py @@ -51,8 +51,16 @@ class JSONField(models.TextField): models.signals.pre_init.connect(self.fix_init_kwarg, sender=cls) def fix_init_kwarg(self, sender, args, kwargs, **signal_kwargs): + # Anything passed in as self.name is assumed to come from a serializer and + # will be treated as a json string. if self.name in kwargs: - kwargs[self.attname] = json.dumps(kwargs.pop(self.name)) + value = kwargs.pop(self.name) + + # Hack to handle the xml serializer's handling of "null" + if value is None: + value = 'null' + + kwargs[self.attname] = value def formfield(self, *args, **kwargs): kwargs["form_class"] = JSONFormField @@ -101,7 +109,8 @@ class SlugMultipleChoiceField(models.Field): del kwargs[k] defaults.update(kwargs) - form_class = forms.TypedMultipleChoiceField + # Django 1.2 does not supply MultipleChoiceField + form_class = getattr(forms, 'TypedMultipleChoiceField', forms.MultipleChoiceField) return form_class(**defaults) def validate(self, value, model_instance):