-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order_by for relationship ? #190
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')
|
This seems to affect what is sortable in the list view. What about managing the sort order in the (dropdown) on the edit view? I can't get those sorted. |
@mistercrunch (and others who find this via Google like me), you could update the def edit_form(self, obj=None):
form = super().edit_form(obj)
# apply a sort to the relation
form.venue.query_factory = lambda: models.Venue.query.order_by(models.Venue.name)
return form |
Hi,
I have two tables, link by a relationship :
When creating a News item, venue objects are displayed in a select, but there are not ordered, how could I do that ?
Thanks you !
The text was updated successfully, but these errors were encountered: