当我拥有EmbeddedDocument对象时,如何访问Document对象? 例如:MongoDB,MongoEngine:如何通过其EmbeddedDocument获取文档?
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我还没有发现这样的事。
没有得到您的问题。你想做什么。 'ToySale'获得'Toy'? – alexvassel