Opened 3 years ago

Last modified 5 weeks ago

#29112 assigned New feature

Make it easier to update specific keys within nested Django JSONField data.

Reported by: Michael Owned by: Priyansh Saxena
Component: contrib.postgres Version: master
Severity: Normal Keywords:
Cc: Tom Forbes Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Django's docs have a great example of querying nested data using double underscore syntax similar to querying across foreign keys

Dog.objects.filter(data__owner__name='Bob')

What if we wanted to update this dogs owner's name instead (without touching anything else)? Rather than doing this

dog = Dog.objects.get(pk=n)
data = dog.data
data['owner']['name'] = 'Steve'
dog.data = data
dog.save()

It would be great to do this:

Dog.objects.filter(pk=2).update(data__owner__name='Steve')

Looks like django-postgres-extensions[0] attempts to do this, but I found the library to be unstable on 1.11.

[0] - http://django-postgres-extensions.readthedocs.io/

Change History (11)

comment:1 Changed 3 years ago by Simon Charette

Triage Stage: UnreviewedAccepted
Version: 1.11master

This is kind of related to #24709 but for JSONField instead of ArrayField.

comment:2 Changed 2 years ago by Priyansh Saxena

Owner: set to Priyansh Saxena
Status: newassigned

comment:3 Changed 2 years ago by Priyansh Saxena

Has patch: set

comment:4 Changed 2 years ago by Tim Graham

Patch needs improvement: set

comment:5 Changed 18 months ago by Tom Forbes

Cc: Tom Forbes added
Owner: changed from Priyansh Saxena to Tom Forbes

comment:6 Changed 16 months ago by Asif Saifuddin Auvi

Owner: changed from Tom Forbes to Asif Saifuddin Auvi

comment:7 Changed 6 weeks ago by Shaurya Shahi

https://stackoverflow.com/q/62561675/2415394

Similar question. Posting here for visibility.

comment:8 Changed 6 weeks ago by Priyansh Saxena

Is this ticket in active development ? If not, I'd like to take it back and finish this off.

comment:9 Changed 6 weeks ago by Asif Saifuddin Auvi

Owner: Asif Saifuddin Auvi deleted
Status: assignednew

plz take this over

comment:10 Changed 6 weeks ago by Priyansh Saxena

Owner: set to Priyansh Saxena
Status: newassigned

comment:11 Changed 5 weeks ago by felixxm

UI/UX: unset
Note: See TracTickets for help on using tickets.
Back to Top