我正在尝试定义一个Flask-Admin类,该类可以是一个独立的可编辑文档,有时是一个别有用心的collection中的embeddableDocument,但是我似乎找不到一个可以让我这样做的类类型。我可以从Flask-Security获得UserMixins和RoleMixins,这使我可以将Roles编辑为独立文档,然后在User类中引用它们,对于EmbeddedDocumentFields可以做到吗?
class Role(db.Document, RoleMixin):
name = db.StringField(max_length=80, unique=True)
description = db.StringField(max_length=255)
class Badge(db.Document): # UserMixin ? RoleMixin ?
name = db.StringField(max_length=60)
description = db.StringField()
default_level = db.StringField(default=1)
icon = db.FileField(required=False)
color_hex = db.StringField()
class User(db.Document, UserMixin):
active = db.BooleanField(default=True)
first_name = db.StringField(max_length=255)
last_name = db.StringField(max_length=255)
email = db.StringField(max_length=255)
password = db.StringField(max_length=255)
confirmed_at = db.DateTimeField()
badges = db.ListField(db.EmbeddedDocumentField(Badge))
roles = db.ListField(db.ReferenceField(Role))
meta = {'strict': False}
谢谢!