Monday, March 27, 2017

Re: Update dict JsonField Postgresql

json.dumps return this (For example, the field contains 50k of records):

[{'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}]



El lunes, 27 de marzo de 2017, 11:28:53 (UTC-3), Melvyn Sopacua escribió:

Hi Martin,

 

On Monday 27 March 2017 07:05:38 Martin Peveri wrote:

> Hi Melvyn, With "not working", I mean that it does nothing. For

> example

>

> This line

>

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

>

> It does not return any errors

>

> This line:

> >>> objectitem.save()

>

> Neither

>

> So when I'm going to get the record back, it returns me the same.

>

> >>> objectitem.data[0]

> >>> False

>

> I would have to return True.

 

Is this really how you typed it? Because objectitem.data[0] should be a dict or list, but not a boolean.

Could you show the output of:

 

json.dumps(objectitem.data)

 

 

> I explain? My English is not very good.

>

> You can explain a little more this: "Django's JSONEncoder only accepts

> dicts as outermost structure."

 

I'm not sure it is used for assigning data to the json field. It is used to form a django.http.JSONResponse and to serialize data to JSON, so that was a guess.

 

> I am inserting a list of dicts. For example:

> >>> Model.objects.create(data={[......my dicts ]}

>

> That's wrong?

 

Not sure, but as you typed it, it's a set, not a dict (there is no 'key':), so if python thinks any of the lists are identifcal, it'll be missing.

 

 

--

Melvyn Sopacua

--
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/49f63d83-7582-4b59-be71-5c35031fd1d3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment