0
如果我有以下模式:如何查询过嵌入文档的列表,allow_inheritance
class Post(EmbeddedDocument):
title = StringField(max_length=120, required=True)
meta = {'allow_inheritance': True}
class TextPost(Post):
content = StringField()
class MoviePost(Post):
author = ReferenceField(Authors)
class Record(Document):
posts = ListField(EmbeddedDocumentField(Post))
我做下面的查询:
author = Author.objects.get_or_404(id = id)
records = Record.objects(posts__author = author)
records.count()
我收到以下错误:
AttributeError: 'author' object has no attribute 'get'
这似乎只发生在allow_inheritance当某些对象可能或不可能有'作者'fie LD。如果该字段存在于所有对象上,如“标题”字段,则查询可以正常工作。