Hi Matt,
Correct, using either null=True or blank=True on the field works.
However, I don't get it since I didn't click on "save", I just wanted to
display the add page containing it. Why does it attempt to validate the
field at this time and not wait for the form to be sent ? Maybe this is how
Django works ?
Whatever, I think you can set a default value in the JSONField to avoid the
error, what do you think ? I think it's handy.
improvement:
def __init__(self, *args, **kwargs):
kwargs['default'] = kwargs.get('default', '{}')
super(JSONField, self).__init__(*args, **kwargs)
It works for me.
Another point: it does not like "extra" comma right ?
{
"nodes": { "title": "title"*,* }
}
But I guess this is wanted because JSON does not allow it ?
Michael
Le mercredi 11 juillet 2012 09:15:23 UTC+2, Matt Schinckel a écrit :
>
> Michael,
>
> I've been able to reproduce it: I'm not quite sure of the best way to deal
> with it.
>
> One solution is to set either null=True, or blank=True on the field, or
> set a default.
>
> The trick is, an empty string isn't valid JSON. I guess I've always been
> using a default (usually of {} or [], depending upon context).
>
> Happy for you to suggest improvements, though.
>
> I believe it's actually related to
> https://bitbucket.org/schinckel/django-jsonfield/issue/13/integrityerrors-when-using-empty-string
>
> Matt.
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/OpX1uuzKTyEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.