问题
I have the following Django model:
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())
I want to add a manytomany field of Feedback in Company
Thanks in advance.
回答1:
This is not a Django model, but a mongoengine Document
. It does not have ManyToManyField
. Instead you should probably add a ReferenceField
inside a ListField
to your Company
class, like this:
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())
Source: http://docs.mongoengine.org/guide/defining-documents.html#one-to-many-with-listfields
来源:https://stackoverflow.com/questions/25567083/manytomany-field-in-django-mongoengine-document