From 70d5e32e13426372d3d98bb7664d8a69975ed885 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 15 Oct 2007 02:54:30 +0000 Subject: queryset-refactor: Made the use of values() for ForeignKey fields consistent and documented this feature. Refs #4358. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6516 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/regressiontests/queries/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/regressiontests/queries/models.py b/tests/regressiontests/queries/models.py index 9b076633c7..6748950f21 100644 --- a/tests/regressiontests/queries/models.py +++ b/tests/regressiontests/queries/models.py @@ -334,5 +334,24 @@ Bug #3037 Bug #5321 >>> Note.objects.values('misc').distinct().order_by('note', '-misc') [{'misc': u'foo'}, {'misc': u'bar'}] + +Bug #4358 +If you don't pass any fields to values(), relation fields are returned as +"foo_id" keys, not "foo". For consistency, you should be able to pass "foo_id" +in the fields list and have it work, too. We actually allow both "foo" and +"foo_id". + +# The *_id version is returned by default. +>>> 'note_id' in ExtraInfo.objects.values()[0] +True + +# You can also pass it in explicitly. +>>> ExtraInfo.objects.values('note_id') +[{'note_id': 1}, {'note_id': 2}] + +# ...or use the field name. +>>> ExtraInfo.objects.values('note') +[{'note': 1}, {'note': 2}] + """} -- cgit v1.3