Opened 4 months ago

Last modified 3 months 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: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: yes

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 (4)

comment:1 Changed 4 months 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 3 months ago by Priyansh Saxena

Owner: set to Priyansh Saxena
Status: newassigned

comment:3 Changed 3 months ago by Priyansh Saxena

Has patch: set

comment:4 Changed 3 months ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top