0

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 ..... !

Youpsla
  • 159
  • 2
  • 13

1 Answers1

2

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',)
iurisilvio
  • 4,868
  • 1
  • 30
  • 36
  • 1
    UNDERSTOOD and thanks a lots for your so quick answer. I should have found this because of the 'n' at the end of the error ! By the way it solved another issue with `nullable=False`in my model definition. I'll do another Post to explain that. – Youpsla Feb 26 '14 at 12:44