minor tweaks to code quality in _fields_to_dbfields
This commit is contained in:
parent
1d4b1870cf
commit
a8d6e59a7a
@ -1722,25 +1722,33 @@ class BaseQuerySet(object):
|
|||||||
return frequencies
|
return frequencies
|
||||||
|
|
||||||
def _fields_to_dbfields(self, fields):
|
def _fields_to_dbfields(self, fields):
|
||||||
"""Translate fields paths to its db equivalents"""
|
"""Translate fields' paths to their db equivalents."""
|
||||||
ret = []
|
|
||||||
subclasses = []
|
subclasses = []
|
||||||
document = self._document
|
if self._document._meta['allow_inheritance']:
|
||||||
if document._meta['allow_inheritance']:
|
|
||||||
subclasses = [get_document(x)
|
subclasses = [get_document(x)
|
||||||
for x in document._subclasses][1:]
|
for x in self._document._subclasses][1:]
|
||||||
|
|
||||||
|
db_field_paths = []
|
||||||
for field in fields:
|
for field in fields:
|
||||||
|
field_parts = field.split('.')
|
||||||
try:
|
try:
|
||||||
field = '.'.join(f if isinstance(f, six.string_types) else f.db_field for f in
|
field = '.'.join(
|
||||||
document._lookup_field(field.split('.')))
|
f if isinstance(f, six.string_types) else f.db_field
|
||||||
ret.append(field)
|
for f in self._document._lookup_field(field_parts)
|
||||||
|
)
|
||||||
|
db_field_paths.append(field)
|
||||||
except LookUpError as err:
|
except LookUpError as err:
|
||||||
found = False
|
found = False
|
||||||
|
|
||||||
|
# If a field path wasn't found on the main document, go
|
||||||
|
# through its subclasses and see if it exists on any of them.
|
||||||
for subdoc in subclasses:
|
for subdoc in subclasses:
|
||||||
try:
|
try:
|
||||||
subfield = '.'.join(f if isinstance(f, six.string_types) else f.db_field for f in
|
subfield = '.'.join(
|
||||||
subdoc._lookup_field(field.split('.')))
|
f if isinstance(f, six.string_types) else f.db_field
|
||||||
ret.append(subfield)
|
for f in subdoc._lookup_field(field_parts)
|
||||||
|
)
|
||||||
|
db_field_paths.append(subfield)
|
||||||
found = True
|
found = True
|
||||||
break
|
break
|
||||||
except LookUpError:
|
except LookUpError:
|
||||||
@ -1748,7 +1756,8 @@ class BaseQuerySet(object):
|
|||||||
|
|
||||||
if not found:
|
if not found:
|
||||||
raise err
|
raise err
|
||||||
return ret
|
|
||||||
|
return db_field_paths
|
||||||
|
|
||||||
def _get_order_by(self, keys):
|
def _get_order_by(self, keys):
|
||||||
"""Given a list of MongoEngine-style sort keys, return a list
|
"""Given a list of MongoEngine-style sort keys, return a list
|
||||||
|
Loading…
x
Reference in New Issue
Block a user