to_db_fields fix (#1553)
This commit is contained in:
parent
2f1fe5468e
commit
1d4b1870cf
@ -1731,14 +1731,14 @@ class BaseQuerySet(object):
|
||||
for x in document._subclasses][1:]
|
||||
for field in fields:
|
||||
try:
|
||||
field = '.'.join(f.db_field for f in
|
||||
field = '.'.join(f if isinstance(f, six.string_types) else f.db_field for f in
|
||||
document._lookup_field(field.split('.')))
|
||||
ret.append(field)
|
||||
except LookUpError as err:
|
||||
found = False
|
||||
for subdoc in subclasses:
|
||||
try:
|
||||
subfield = '.'.join(f.db_field for f in
|
||||
subfield = '.'.join(f if isinstance(f, six.string_types) else f.db_field for f in
|
||||
subdoc._lookup_field(field.split('.')))
|
||||
ret.append(subfield)
|
||||
found = True
|
||||
|
@ -197,14 +197,18 @@ class OnlyExcludeAllTest(unittest.TestCase):
|
||||
title = StringField()
|
||||
text = StringField()
|
||||
|
||||
class VariousData(EmbeddedDocument):
|
||||
some = BooleanField()
|
||||
|
||||
class BlogPost(Document):
|
||||
content = StringField()
|
||||
author = EmbeddedDocumentField(User)
|
||||
comments = ListField(EmbeddedDocumentField(Comment))
|
||||
various = MapField(field=EmbeddedDocumentField(VariousData))
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
post = BlogPost(content='Had a good coffee today...')
|
||||
post = BlogPost(content='Had a good coffee today...', various={'test_dynamic':{'some': True}})
|
||||
post.author = User(name='Test User')
|
||||
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
|
||||
post.save()
|
||||
@ -215,6 +219,9 @@ class OnlyExcludeAllTest(unittest.TestCase):
|
||||
self.assertEqual(obj.author.name, 'Test User')
|
||||
self.assertEqual(obj.comments, [])
|
||||
|
||||
obj = BlogPost.objects.only('various.test_dynamic.some').get()
|
||||
self.assertEqual(obj.various["test_dynamic"].some, True)
|
||||
|
||||
obj = BlogPost.objects.only('content', 'comments.title',).get()
|
||||
self.assertEqual(obj.content, 'Had a good coffee today...')
|
||||
self.assertEqual(obj.author, None)
|
||||
|
Loading…
x
Reference in New Issue
Block a user