我有两节课分&用户。用户属于某个分支。但是每个分支都有一个CEO(一种用户)。但是,当我设计mongokit类并尝试使用引用时,它确实适用于类User(因为分支是在User之前定义的),但它不适用于类Branch,收到以下错误:
'ceo':用户 NameError:名称“用户”未定义
from mongokit import *
from datetime import datetime, date, time
import pprint
db = Connection()
@db.register
class Registry(Document):
structure = {
'created': datetime,
'updated': datetime,
'deleted': datetime
}
@db.register
class Branch(Registry):
structure = {
'name':unicode,
'groupEmail':unicode,
'timezone':unicode,
'address': {
'address1':unicode,
'address2':unicode,
'city':unicode,
'state':unicode,
'country':unicode,
'zip': unicode
},
'size':int,
'ceo': User
}
@db.register
class User(Document):
structure = {
'fname': unicode,
'lname': unicode,
'branch': Branch,
'address': {
'address1':unicode,
'address2':unicode,
'city':unicode,
'state':unicode,
'country':unicode,
'zip': unicode
},
'created': datetime,
'updated': datetime,
'deleted': datetime
}