#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 Changed 17 months ago by Wraithan

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to duplicate
  • Status changed from new to closed

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