【发布时间】:2013-10-10 19:02:57
【问题描述】:
当我拥有 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 中我没有找到类似的东西。
【问题讨论】:
-
没有得到你的问题。你想做什么。通过
ToySale获取Toy?
标签: python mongodb pymongo mongoengine