Opened 7 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.
Change History (13)
comment:1 by , 7 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.11 → master |
comment:2 by , 7 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:4 by , 7 years ago
Patch needs improvement: | set |
---|
comment:5 by , 6 years ago
Cc: | added |
---|---|
Owner: | changed from | to
comment:6 by , 6 years ago
Owner: | changed from | to
---|
comment:7 by , 4 years ago
https://stackoverflow.com/q/62561675/2415394
Similar question. Posting here for visibility.
comment:8 by , 4 years ago
Is this ticket in active development ? If not, I'd like to take it back and finish this off.
comment:10 by , 4 years ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:12 by , 4 years ago
Component: | contrib.postgres → Database layer (models, ORM) |
---|---|
Owner: | removed |
Status: | assigned → new |
comment:13 by , 3 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Marking as a duplicate of #32519, with a more comprehensive discussion.
This is kind of related to #24709 but for
JSONField
instead ofArrayField
.