flask-admin
flask-admin copied to clipboard
FlaskAdmin issues with EmbeddedDocuments
I'm using mongoengine and I have some issues when using Flask Admin.
If I have a Embedded document or ReferenceObject, the admin just shows EMail object or User object or <class_name> object in general. Seems as though these are just being converted to strings - which is not a very correct way to do this.
When I try to create a model which has a Reference field, I get a drop down with every element as User Object - which is very confusing as I have no idea what their id is !
For displaying I suggest you use links with the Object id or something.
You have to overload a method __str__ (for Python 3) or __unicode__ (for Python 2):
# for python3
class Email (db.Document):
value = db.StringField()
def __str__(self):
return self.value
class User (db.Document):
name = db.StringField()
email = db.ReferenceField(Email)
def __str__(self):
return 'My name is %s and email is %s' % (self.name, self.email.value)