How can I show SQLA relationships in flask-admin?

23 Views Asked by At

I have searched online for solutions but I can't seem to find one.

I have this Articles model:

class Articles(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    title = db.Column(db.String(35), nullable=False)
    body = db.Column(db.Text, nullable=False)
    tags = db.Column(db.String(200), nullable=False)
    approved = db.Column(db.Boolean, nullable=False, default=False)
    thumbnail = db.Column(db.String(200), nullable=True)
    slug = db.Column(db.String(100), nullable=False, default='id-title')
    category = db.Column(db.String(75), nullable=False, default='light')
    created = db.Column(db.DateTime, default=datetime.utcnow)

    author_id = db.Column(db.Integer, db.ForeignKey('users.id')) 
    author = db.relationship('Users', foreign_keys=author_id)

And this view:

class AllArticlesModelView(ModelView):
    def is_accessible(self):
        return current_user.is_admin()`

Whenever I modify an article from flask-admin I get an error beacuse "author" is NoneType. How can I select an author by it's username in there?

0

There are 0 best solutions below