我有以下Django模型:
from mongoengine import *
from datetime import datetime
class Company(Document):
name = StringField(max_length=500)
class Feedback(Document):
text = StringField(max_length=500)
is_approved = BooleanField(default=False)
date = DateTimeField(default=datetime.now())
我想在公司中添加许多反馈字段
提前致谢。
答案 0 :(得分:4)
这不是Django模型,而是mongoengine Document
。它没有ManyToManyField
。相反,您应该在ReferenceField
类ListField
内添加Company
,如下所示:
class Company(Document):
name = StringField(max_length=500)
feedbacks = ListField(ReferenceField(Feedback))
class Feedback(Document):
text = StringField(max_length=500)
is_approved = BooleanField(default=False)
date = DateTimeField(default=datetime.now())
来源:http://docs.mongoengine.org/guide/defining-documents.html#one-to-many-with-listfields