Tuesday, March 28, 2017

Re: Update dict JsonField Postgresql

It does not work :(

With ArrayField Will I be able to filter the content of the field?. For example, if i have one record and in the field data a list of dict with 50k. Can I filter it?. That is to say, to bring only in the array the records with 'processed' true.

Thanks! 

El martes, 28 de marzo de 2017, 6:58:51 (UTC-3), Melvyn Sopacua escribió:

On Monday 27 March 2017 15:03:17 Martin Peveri wrote:

> Perfect!! This code works:

>

> data = objectitem.data

>

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

>

> objectitem.data = data

>

> objectitem.save()

>

> A last query that is not related to the insertion, but to the query.

>

> If I want to get only records processed in True as I have to do?

>

> This does not work, I get all the records:

>

> objectitem.filter(data__contains=[{'processed': True}])

 

Looking at your data model, you should probably make data an ArrayField of JSONFields...

This would simplify things quite a bit.

 

That said, I would try data__contains={'processed': True}, but if that doesn't work, your problem is that your outer structure is a list, not an object, making filtering a lot harder.

 

--

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/403307f0-2cf6-4e73-b979-558c279a1450%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment