Monday, March 27, 2017

Re: Update dict JsonField Postgresql

Hi,

 

On Monday 27 March 2017 08:50:04 Martin Peveri wrote:

 

Totally forgot about this gotcha:

 

> > > >>> objectitem.data[0]['processed'] = True

 

That won't work.

objectitem.data is a reference to a list of dicts

changing something inside, doesn't signal the model that it's data has changed, as the reference doesn't change.

 

You need to manipulate the data as it's own structure, then assign it:

 

data = objectitem.data

data[0]['processed'] = True

objectitem.data = data

objectitem.save()

 

If the above don't work:

objecitem.save(force_update=True, update_fields=('data',))

 

 

--

Melvyn Sopacua

No comments:

Post a Comment