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'}]

Change History (1)

comment:1 by Wraithan, 11 years ago

Resolution: duplicate
Status: newclosed

Eric Holscher found that this already exists, closing duplicate.

https://code.djangoproject.com/ticket/16735

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