我有模型:
from flask.ext.security import currennt_user
#instance of LocalProxy wrapped model User(db.Document)
class ContactModel(db.Document, SomeMixin):
user = db.ReferenceField(User, verbose_name='User', required=True)
并面临 ReferenceField 的奇怪行为。为什么使用以下代码:
model = ContactModel(user = current_user.pk, ....)
并且不遵循:
model = ContactModel()
model.user = current_user.pk
当我尝试做同样的问题时:model = ContactModel() model.user = current_user
最后两段代码抛出错误:ValidationError: ValidationError (ContactModel:None) (A ReferenceField only accepts DBRef or documents: ['user'])