QuerySet.only field name translation and polymorphism fix

This commit is contained in:
Harry Marr
2010-02-26 19:43:26 +00:00
parent 200e9eca92
commit 265776566e
2 changed files with 45 additions and 1 deletions

View File

@@ -456,7 +456,18 @@ class QuerySet(object):
:param *fields: fields to include
"""
self._loaded_fields = list(fields)
self._loaded_fields = []
for field in fields:
if '.' in field:
raise InvalidQueryError('Subfields cannot be used as '
'arguments to QuerySet.only')
# Translate field name
field_name = QuerySet._lookup_field(self._document, field)[-1].name
self._loaded_fields.append(field_name)
# _cls is needed for polymorphism
if self._document._meta.get('allow_inheritance'):
self._loaded_fields += ['_cls']
return self
def order_by(self, *keys):