我在名为model.py
的文件中有以下架构from mongoengine import *
class Subject(Document):
uri = StringField(required=True)
resources = ListField(ReferenceField(ResourceSubject))
class ResourceSubject(Document):
subject = ReferenceField(Subject,reverse_delete_rule=CASCADE)
resource = ReferenceField(Resource)
class Resource(EmbeddedDocument):
uri = StringField()
title = StringField()
snippet = StringField()
image = StringField()
source = StringField()
adapter = StringField()
出于某种原因,当我尝试初始化主题时,subj = Subject(uri="hello").save()
我收到了一个名称错误:NameError: name 'ResourceSubject' is not defined
。
我无法理解原因,我猜这与框架有关?我尝试在单个文件中分离类然后导入,但我仍然得到相同的错误。我错过了什么?
此行上出现错误:resources = ListField(ReferenceField(ResourceSubject))
答案 0 :(得分:3)
将ResourceSubject
放入引号:
resources = ListField(ReferenceField('ResourceSubject'))