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 x in document._subclasses][1:]
|
||||||
for field in fields:
|
for field in fields:
|
||||||
try:
|
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('.')))
|
document._lookup_field(field.split('.')))
|
||||||
ret.append(field)
|
ret.append(field)
|
||||||
except LookUpError as err:
|
except LookUpError as err:
|
||||||
found = False
|
found = False
|
||||||
for subdoc in subclasses:
|
for subdoc in subclasses:
|
||||||
try:
|
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('.')))
|
subdoc._lookup_field(field.split('.')))
|
||||||
ret.append(subfield)
|
ret.append(subfield)
|
||||||
found = True
|
found = True
|
||||||
|
@ -197,14 +197,18 @@ class OnlyExcludeAllTest(unittest.TestCase):
|
|||||||
title = StringField()
|
title = StringField()
|
||||||
text = StringField()
|
text = StringField()
|
||||||
|
|
||||||
|
class VariousData(EmbeddedDocument):
|
||||||
|
some = BooleanField()
|
||||||
|
|
||||||
class BlogPost(Document):
|
class BlogPost(Document):
|
||||||
content = StringField()
|
content = StringField()
|
||||||
author = EmbeddedDocumentField(User)
|
author = EmbeddedDocumentField(User)
|
||||||
comments = ListField(EmbeddedDocumentField(Comment))
|
comments = ListField(EmbeddedDocumentField(Comment))
|
||||||
|
various = MapField(field=EmbeddedDocumentField(VariousData))
|
||||||
|
|
||||||
BlogPost.drop_collection()
|
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.author = User(name='Test User')
|
||||||
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
|
post.comments = [Comment(title='I aggree', text='Great post!'), Comment(title='Coffee', text='I hate coffee')]
|
||||||
post.save()
|
post.save()
|
||||||
@ -215,6 +219,9 @@ class OnlyExcludeAllTest(unittest.TestCase):
|
|||||||
self.assertEqual(obj.author.name, 'Test User')
|
self.assertEqual(obj.author.name, 'Test User')
|
||||||
self.assertEqual(obj.comments, [])
|
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()
|
obj = BlogPost.objects.only('content', 'comments.title',).get()
|
||||||
self.assertEqual(obj.content, 'Had a good coffee today...')
|
self.assertEqual(obj.content, 'Had a good coffee today...')
|
||||||
self.assertEqual(obj.author, None)
|
self.assertEqual(obj.author, None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user