當我擁有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