From 94fe48e2817909cbb02f479b2ac691205483a151 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Fri, 22 Dec 2017 21:02:54 +0100 Subject: [PATCH] Return select field choices ordered by attribute --- app/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/utils.py b/app/utils.py index e2c78dc..dd9fbec 100644 --- a/app/utils.py +++ b/app/utils.py @@ -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 -- GitLab