将此代码添加到已被其他模型引用的每个模型中,flask-admin 和 jinja 将处理您要在屏幕上显示的名称,只需将其替换为您喜欢的任何名称:
def __unicode__(self):
return self.name # or self.id or whatever you prefer
例如:
class Role(db.Document, RoleMixin):
name = db.StringField(max_length=80, unique=True)
description = db.StringField(max_length=255)
def __unicode__(self):
return self.name
class MasterUser(db.Document, UserMixin):
email = db.StringField(max_length=255)
password = db.StringField(max_length=255)
active = db.BooleanField(default=True)
confirmed_at = db.DateTimeField()
roles = db.ListField(db.ReferenceField(Role), default=[])