I've got a model with a JSONField (a Postgres only field):
models.py:
from django.db import models
from django.contrib.postgres.fields import JSONField
class Mod(models.Model):
data = JSONField(default={ 'name':'Model' })
So I create 2 models – ./manage.py shell
:
>>> from m3d.models import Mod
>>> m1 = Mod()
>>> m1.save()
>>> m2 = Mod()
>>> m2.data['name'] = 'Model 2'
>>> m2.save()
But they have the same data['name']
values:
>>> m1.data['name']
'Model 2'
>>> m2.data['name']
'Model 2'
Note that the values are different in the database:
>>> m1a = Mod.objects.get(pk=m1.pk) # get m1 data from db
>>> m1a.data['name']
'Model'
>>> m2.data['name']
'Model 2'
but the variable m1
still has the value Model 2
.
Am I missing something? Is this some sort behavior I'll need to work around?
FYI: Using Django 2.0.1