Skip to content

Instantly share code, notes, and snippets.

@kbussell
Last active Sep 24, 2016
Embed
What would you like to do?
In [1]: j = JsonModel.objects.create(data={'some': 'data'})
In [2]: j.id
Out[2]: 1
In [3]: repr(j.data)
Out[3]: "{'some': 'data'}"
In [4]: j.save()
In [5]: j = JsonModel.objects.get(id=1)
In [6]: repr(j.data)
Out[6]: '\'{"some": "data"}\''
In [7]: j.save()
In [8]: j = JsonModel.objects.get(id=1)
In [9]: repr(j.data)
Out[9]: '\'"{\\\\"some\\\\": \\\\"data\\\\"}"\''
from django.contrib.postgres.fields import JSONField
from django.db import models
class JsonModel(models.Model):
data = JSONField()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment