Opened 11 years ago
Closed 11 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 |
Description
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)
Example:
MyModel.objects.values('slug', field='related__field') # [{'slug': 'first-slug', 'field': 'related field data'}]
Note:
See TracTickets
for help on using tickets.
Eric Holscher found that this already exists, closing duplicate.
https://code.djangoproject.com/ticket/16735