[英]ReferenceField in mongoengine
I use mongoengine with django. 我将mongoengine与django结合使用。 I have two applications with models.
我有两个带有模型的应用程序。
app1/models.py
: app1/models.py
:
from mongoengine import fields
from mongoengine.document import Document
class Model1(Document):
name = fields.StringField()
lists = fields.ListField(fields.ReferenceField("Model2", dbref=False))
app2/models.py
: app2/models.py
:
from mongoengine import fields
from mongoengine.document import Document
class Model2(Document):
name = fields.StringField()
All applications were added to INSTALLED_APPS
. 所有应用程序均已添加到
INSTALLED_APPS
。 When I use the django dev-server, everything is fine. 当我使用django dev-server时,一切都很好。 But using this code with uwsgi-server there is an error:
但是在uwsgi-server上使用此代码会出现错误:
Model2 has not been registered in the document registry.
Importing the document class automatically registers it, has it
been imported?
What I should do? 我该做什么?
You should import app2.models
somewhere. 您应该
app2.models
某个地方导入app2.models
。 Put a comment by the import saying why it's there, so nobody removes the useless-looking import in the future. 在导入内容中添加评论,说明其为什么存在,因此将来没人会删除看起来无用的导入内容。
When the django dev server starts up it imports the models from all installed apps and validates them. django开发服务器启动时,它将从所有已安装的应用程序中导入模型并进行验证。 You'll see
你会看到的
Validating models...
0 errors found
This does not happen in a production environment. 在生产环境中不会发生这种情况。 It is just a nicety of the dev server.
这只是开发服务器的优点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.