librelist archives

« back to archive

How can I solve this error from flask-admin extension when creating a ModelView?

How can I solve this error from flask-admin extension when creating a ModelView?

From:
Kush Goyal
Date:
2013-11-02 @ 13:48
Hi,

I am going through the flask-admin tutorial on
http://flask-admin.readthedocs.org/en/latest/quickstart/

As the tutorial explains, when I create an instance of ModelView for
my User model by using

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

I get an error which is: AttributeError: 'ColumnProperty' object has
no attribute 'expression'

and when I create an instance of ModelView for my Account model by using:

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

I get an error: Exception: Model Account does not have primary key.

My User model code is:

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80))
    email = db.Column(db.String(160))
    password = db.Column(db.String(100))
    account_id = db.Column(db.Integer, db.ForeignKey('account.id'))
    account = db.relationship('Account', backref=db.backref('user',
lazy='dynamic'))

Account model code is:

class Account(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    password = db.Column(db.String(100))

I am using flask-sqlalchemy for creating models. Can someone please
suggest how to solve these errors?

Thanks!

Kush