更新された問題は解決しました。ここにいくつかの設計上の問題があります。
ディレクトリは次のようになります。
/view
|-__init__.py
|-quiz.py
|-test.py
|-user.py
そして問題は、で、からquiz.py
をインポートすることです。で、からをインポートします。class
test
test.py
class
quiz
更新:変更しましimport
たが、まだありますAttributeError
次のようなコード:
quiz.py
#ignore some imports here
import test
from user import User
class Quiz(Document):
creator = ReferenceField(User, reverse_delete_rule=CASCADE)
info = GenericEmbeddedDocumentField("QuizInfo")
description = StringField(max_length=100)
attachment = GenericEmbeddedDocumentField("QuizAttach")
correctanswer = GenericEmbeddedDocumentField("QuizAnswer")
wronganswer = GenericEmbeddedDocumentField("QuizAnswer")
manualdifficulty= FloatField(min_value=0, max_value=1)
autodifficulty = FloatField(min_value=0, max_value=1)
checkout = GenericEmbeddedDocumentField("QuizCheckcout")
tag = ListField(StringField(max_length=20))
#ignore some codes here
class QuizCheckout(EmbeddedDocument):
time = DateTimeField()
type = IntField()
description = StringField()
test = ReferenceField(test.Test, reverse_delete_rule=CASCADE)
test.py
import quiz
class Test(Document):
createdate = DateTimeField() #Create datetime
description = StringField() #decription of this test
takennumber = IntField() #the number of students who may take this test
quiz = GenericEmbeddedDocumentField('TestQuiz')
class TestQuiz(EmbeddedDocument):
quiz = ListField(ReferenceField(quiz.Quiz, reverse_delete_rule=CASCADE))
#Reference to Quiz, if Quiz is deleted, this reference will be deleted too.
correct = IntField()
#how many students got this right
エラーは
Exception Type: AttributeError Exception
Value: 'module' object has no attribute 'Quiz'
最初は再帰的な問題かもしれないと思ったのですが、import
再帰的なインポートを避けるために関数に移動できただけですが、ここには関数がなく、import
クラスに移動しようとすると機能しません。
これらの定義を別のファイルに保持する方法はありますか?