Question

first of all, I'm not python proof.

I'm not sure to really understand the following sentence about the ModelView in the doc (http://flask-admin.readthedocs.org/en/latest/api/mod_contrib_sqla/) :

Class inherits configuration options from BaseModelView and they’re not displayed here

As far I understand, a class which inherit from ModelView should inherits configurations options from BaseModelView

BaseModelView has a form_columns method. Then I don't understand why I got the following error ValueError: Invalid model property name <class 'app.models.Idcard'>.n with the following code:

models.py

class Idcard(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    name = db.Column(db.String(128), nullable=False)

    def __repr__(self):
        return '%s' % unicode(self.name)

views.py

class IdcardView(ModelView):
    form_columns = ('name')

admin.add_view(IdcardView(Idcard, db.session)

As far I understand the error, the problem comes from the name in form_columns = ('name') butthis is clearly a parameter of my model Class Idcard.

If somebody has an idea ..... !

Was it helpful?

Solution

The form_columns property receive a tuple. A tuple with one item need a comma: ('name',).

Without the comma, it is just a string and flask-admin failed iterating each char (the first one is a n).

So, just change:

class IdcardView(ModelView):
    -form_columns = ('name')
    +form_columns = ('name',)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top