id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 5293 adding sql functions to order_by clause handling rb.online@… nobody "The attached patch enables the use of a sql function in a order_by clause. example: Publication.objects.order_by(""-year(date)"") will produce the following SQL: ... ORDER BY YEAR(date) DESC use case: when ordering according to multiple fields to group by year, and then say by publication type, if we use the date to order, the publication type is used only if the whole date is the same. to group publications by year in the order clause, I could not find a solution. Publication.objects.order_by(""-date.year"", ""author"") does not work but Publication.objects.order_by(""-year(date)"", ""author"") does. I suspect there are other use cases. caveats: The provided patch does not changes the way the deprecated syntax for ordering is handled (in orderlist2sql)" closed Core (Other) dev wontfix order_by sam@… Design decision needed 1 0 1 0 0 0