当我拥有文档对象的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”机制,但在mongoengineorm中我没有发现类似的东西。在
您可以通过
EmbeddedDocument
字段获取文档。在例如,
end_time
:由
^{pr2}$percentage
:双方:
如果您已经有
EmbeddedDocument
,例如toy_sale
,您可以这样做:或者只是:
请参阅文档:http://mongoengine-odm.readthedocs.org/en/latest/guide/querying.html#filtering-queries。在
问题解决了。在
相关问题 更多 >
编程相关推荐