Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FlaskAdmin issues with EmbeddedDocuments #19

Open
AbdealiLoKo opened this issue Jan 8, 2016 · 1 comment
Open

FlaskAdmin issues with EmbeddedDocuments #19

AbdealiLoKo opened this issue Jan 8, 2016 · 1 comment

Comments

@AbdealiLoKo
Copy link

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.

@ypopivniak
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants