当我拥有 EmbeddedDocument 对象时,如何访问 Document 对象?例如:
class ToySale(EmbeddedDocument):
end_time = FloatField()
percentage = IntField()
@property
def super_price(self):
# I want to get access to Toy Document, something like that
return self.toy.price - (self.percentage * self.toy.price / 100)
class Toy(Document)
sale = EmbeddedDocumentField(ToySale)
price = IntField()
Django ORM 有类似的 'related_name' 机制,但在 mongoengine ORM 中我没有找到类似的东西。