Opened 10 years ago

Closed 10 years ago

#24084 closed New feature (duplicate)

Alias related properties inside values()

Reported by: Bibhas C Debnath Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Right now we can use values() to fetch properties like this -

>>> Entry.objects.values('blog')
[{'blog': 1}, ...]

But I have a case where I need to fetch a property from a related mode so I'm doing this -

>>> Boundary.objects.values('id', 'school__liblangagg__class_name')
[{'school__liblangagg__class_name': 6, 'id': 8999}, {'school__liblangagg__class_name': 5, 'id': 8954}, {'school__liblangagg__class_name': 3, 'id': 9000}, {'school__liblangagg__class_name': 2, 'id': 8942},]

It'd be really convenient if I could alias the related property. Something like this -

>>> Boundary.objects.values('id', ('class_name', 'school__liblangagg__class_name'))
[{'class_name': 6, 'id': 8999}, ... ]

So in place of the string representing the related property, we could have a tuple (alias, related_string). The output looks a bit ugly to pass this on to somewhere and it's a bit of work to iterate over all of them and replace the key.

Does it seem like a feature worth considering?

Change History (1)

in reply to:  description comment:1 by Simon Charette, 10 years ago

Resolution: duplicate
Status: newclosed

Does it seem like a feature worth considering?

Yes, this is duplicate of #16735.

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