From f10b6f4f0b57f80558d4be798ebed09e4735bead Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 21 2018 20:43:28 +0000 Subject: Make the most recent flags appear at the top By inverting the order in which pull_request.flags returns the flags and ensure this order is based on the date_created, we ensure that the most recently added flags appear at the top when showing them on PRs, rather than having them order by update date/time. Fixes https://pagure.io/pagure/issue/3656 Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/lib/model.py b/pagure/lib/model.py index 7ade5a5..5aa0093 100644 --- a/pagure/lib/model.py +++ b/pagure/lib/model.py @@ -2234,7 +2234,11 @@ class PullRequestFlag(BASE): pull_request = relation( "PullRequest", - backref=backref("flags", cascade="delete, delete-orphan"), + backref=backref( + "flags", + order_by=str("(pull_request_flags.c.date_created).desc()"), + cascade="delete, delete-orphan" + ), foreign_keys=[pull_request_uid], remote_side=[PullRequest.uid], )