Opened 4 years ago

Closed 4 years ago

#21686 closed New feature (duplicate)

queryset.values() should let you name the resulting key

Reported by: Wraithan Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords: queryset, values, key, naming
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


Let me start by apologizing if this is already a ticket, I tried searching but 'queryset' and 'values' are both very common in tickets.

I propose that queryset.values() should work like queryset.annotate() where you can use kwargs to name the resulting key. My primary use case is when I am building custom JSON endpoints and I want to expose a related field to the front end, I'd like to rename the key to something shorter (but still contextually descriptive)


MyModel.objects.values('slug', field='related__field')
# [{'slug': 'first-slug', 'field': 'related field data'}]

Change History (1)

comment:1 Changed 4 years ago by Wraithan

Resolution: duplicate
Status: newclosed

Eric Holscher found that this already exists, closing duplicate.

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