[Django] #24084: Alias related properties inside values()

10 views
Skip to first unread message

Django

unread,
Jan 6, 2015, 1:33:42 AM1/6/15
to django-...@googlegroups.com
#24084: Alias related properties inside values()
----------------------------------------------+--------------------
Reporter: iambibhas | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/24084>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 6, 2015, 2:21:39 AM1/6/15
to django-...@googlegroups.com
#24084: Alias related properties inside values()
-------------------------------------+-------------------------------------
Reporter: iambibhas | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by charettes):

* status: new => closed
* needs_better_patch: => 0
* resolution: => duplicate
* needs_tests: => 0
* needs_docs: => 0


Comment:

> Does it seem like a feature worth considering?

Yes, this is duplicate of #16735.

--
Ticket URL: <https://code.djangoproject.com/ticket/24084#comment:1>

Reply all
Reply to author
Forward
0 new messages