1
0
mirror of https://github.com/django/django.git synced 2025-10-30 09:06:13 +00:00

Allow "pk" as a field alias in QuerySet.only() calls.

Thanks to GDorn for the patch. Fixed #15494.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16668 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Malcolm Tredinnick
2011-08-23 06:29:01 +00:00
parent a86dde20f0
commit 7182cd2284
2 changed files with 15 additions and 2 deletions

View File

@@ -1791,13 +1791,18 @@ class Query(object):
existing immediate values, but respects existing deferrals.)
"""
existing, defer = self.deferred_loading
field_names = set(field_names)
if 'pk' in field_names:
field_names.remove('pk')
field_names.add(self.model._meta.pk.name)
if defer:
# Remove any existing deferred names from the current set before
# setting the new names.
self.deferred_loading = set(field_names).difference(existing), False
self.deferred_loading = field_names.difference(existing), False
else:
# Replace any existing "immediate load" field names.
self.deferred_loading = set(field_names), False
self.deferred_loading = field_names, False
def get_loaded_field_names(self):
"""