Flask-admin: Order_by for relationship ?

Created on 18 Mar 2013  路  3Comments  路  Source: flask-admin/flask-admin

Hi,
I have two tables, link by a relationship :

class News(db.Model):
   #[...]
    venue_id = db.Column(db.Integer(), db.ForeignKey(Venue.id))
    venue = db.relationship(Venue, backref='news')

When creating a News item, venue objects are displayed in a select, but there are not ordered, how could I do that ?

Thanks you !

Most helpful comment

All you have to do is to tell Flask-Admin which field to use for sorting. By default Flask-Admin won't make any assumptions about it.

This is snippet from sqla:

class PostAdmin(sqlamodel.ModelView):
    # List of columns that can be sorted. For 'user' column, use User.username as
    # a column.
    column_sortable_list = ('title', ('user', User.username), 'date')

user is relation to the User table. If you wish, you can point it to User.id too.

All 3 comments

All you have to do is to tell Flask-Admin which field to use for sorting. By default Flask-Admin won't make any assumptions about it.

This is snippet from sqla:

class PostAdmin(sqlamodel.ModelView):
    # List of columns that can be sorted. For 'user' column, use User.username as
    # a column.
    column_sortable_list = ('title', ('user', User.username), 'date')

user is relation to the User table. If you wish, you can point it to User.id too.

This seems to affect what is sortable in the list view. What about managing the sort order in the