Opened 6 years ago

Closed 3 years ago

#29112 closed New feature (duplicate)

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

Reported by: Michael Owned by:
Component: Database layer (models, ORM) Version: dev
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 (13)

comment:1 by Simon Charette, 6 years ago

Triage Stage: UnreviewedAccepted
Version: 1.11master

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

comment:2 by Priyansh Saxena, 6 years ago

Owner: set to Priyansh Saxena
Status: newassigned

comment:3 by Priyansh Saxena, 6 years ago

Has patch: set

comment:4 by Tim Graham, 6 years ago

Patch needs improvement: set

comment:5 by Tom Forbes, 5 years ago

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

comment:6 by Asif Saifuddin Auvi, 5 years ago

Owner: changed from Tom Forbes to Asif Saifuddin Auvi

comment:7 by Shaurya Shahi, 4 years ago

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

Similar question. Posting here for visibility.

comment:8 by Priyansh Saxena, 4 years ago

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

comment:9 by Asif Saifuddin Auvi, 4 years ago

Owner: Asif Saifuddin Auvi removed
Status: assignednew

plz take this over

comment:10 by Priyansh Saxena, 4 years ago

Owner: set to Priyansh Saxena
Status: newassigned

comment:11 by Mariusz Felisiak, 4 years ago

UI/UX: unset

comment:12 by Mariusz Felisiak, 3 years ago

Component: contrib.postgresDatabase layer (models, ORM)
Owner: Priyansh Saxena removed
Status: assignednew

comment:13 by Mariusz Felisiak, 3 years ago

Resolution: duplicate
Status: newclosed

Marking as a duplicate of #32519, with a more comprehensive discussion.

Note: See TracTickets for help on using tickets.
Back to Top