开发者

mongoengine cross object links

I'll really new in mongo and mongoengine. I'll whant to create object like this:

class Candle(Document):
    value = IntField()
    next = ReferenceField(Candle)
  开发者_JAVA技巧  prev = ReferenceField(Candle)

For using like this:

if Candle.value > Candle.next.value:
    do smf

Is it possible? I'll really glad to see some useful answers.


You need to use the string 'self' as the argument to ReferenceField when you're referring to the class being defined.


Just add the same issue, and I found the solution. I know it's been a while since the question has been asked, but it still may be usefull for some people.

Try:

class Candle(Document):
    value = IntField()
    next = ReferenceField('Candle')
    prev = ReferenceField('Candle')

Using quotes will avoid circular imports and everything should work as wanted.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜