Monday, March 27, 2017

Update dict JsonField Postgresql

Hi everyone, I have a model model like this:


class ItemCampaign(models.Model):

   campaign = models.ForeignKey(
       Campaign, related_name="itemscampaign", verbose_name="Item campaña"
   )
   data = JSONField(default=dict)

   def __str__(self):
       return self.campaign.name

The field data, contains this list dict, for example:

[{'number': '1160188479', 'id': 0, 'content': 'hello', 'processed': False}, {'number': '1160188479', 'id': 1, 'content': 'hello', 'processed': False}, {'number': '1160188479', 'id': 2, 'content': 'hello', 'processed': False}, {'number': '1162341721', 'id': 3, 'content': 'hello', 'processed': False}, {'number': '1162341721', 'id': 4, 'content': 'hello', 'processed': False}, {'number': '1162341721', 'id': 5, 'content': 'hello', 'processed': False}}

I wish make is update one dict of this list:

objectitem.data[0]['processed'] =True
objectitem
.save()


But not working.

Any Idea?.

Thanks!

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/92a4e1aa-6d02-4689-bea1-573c4b7720f7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment