JSONField with blank/null value?

1,103 views
Skip to first unread message

Jeff Johnson

unread,
Apr 4, 2017, 9:51:15 AM4/4/17
to Django REST framework
Hi,

I've been struggling to save a null value to a Postgres 9.6 JSON field using DRF.  I'm testing with the Browsable API if that makes a difference.


class MyModel(models.Model):
    data = JSONField(blank=True, null=True)


class MyModelSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = MyModel
        fields = (
            'url',
            'data',
        )

The validator says "Value must be valid JSON." when I leave the value blank.  
I've tried every combination of required, allow_null, default that I can think of and nothing works.

Any help?

Thanks,
Jeff
Reply all
Reply to author
Forward
0 new messages