Skip to content
Snippets Groups Projects
Commit 94fe48e2 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Return select field choices ordered by attribute

parent 92e8d6ac
No related branches found
No related tags found
No related merge requests found
......@@ -130,7 +130,7 @@ def get_model_choices(model, allow_none=False, attr='name', query=None):
if allow_none:
choices = [(None, '')]
if query is None:
query = model.query
query = model.query.order_by(getattr(model, attr))
choices.extend([(str(instance.id), getattr(instance, attr)) for instance in query.all()])
return choices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment