Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flask-admin not showing foreignkey columns

class Parent(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(120))

    def __repr_(self):
        return '<Parent %r>' % (self.name)

admin.add_view(ModelView(Parent, db.session))


class Child(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    name = db.Column(db.String(120))
    parent = db.Column(db.Integer, db.ForeignKey(Parent))

admin.add_view(ModelView(Child, db.session))

Hello -

The code above is an example of flask-admin page that I am trying to create. The goal is to have on Child's create page a text box for name and a drop down to select a parent.

With the above setup, there is only name field. The parent drop down box is missing.

Any ideas how to make it happen?

like image 840
screenshot345 Avatar asked Apr 23 '13 03:04

screenshot345


1 Answers

For what it is worth, none of the solutions listed here worked for me. I was facing the issue where foreign keys were not showing up in Flask-Admin.

This is what worked for them to show up:

class CustomModelViewName(ModelView):
    can_delete = True
    column_hide_backrefs = False
    column_list = ["column_name", "column_name", "etc", "etc", "etc"]
    column_searchable_list = ["column_name"]
like image 96
Ali Avatar answered Oct 19 '22 02:10

Ali