coalesce-desc-sord

This commit is contained in:
Untone 2024-02-29 15:52:36 +03:00
parent 978595c246
commit bd905021ae

View File

@ -2,6 +2,7 @@ import time
from sqlalchemy import and_, select, desc from sqlalchemy import and_, select, desc
from sqlalchemy.orm import joinedload from sqlalchemy.orm import joinedload
from sqlalchemy.sql.functions import coalesce
from orm.author import Author from orm.author import Author
from orm.rating import is_negative, is_positive from orm.rating import is_negative, is_positive
@ -31,7 +32,7 @@ async def get_shouts_drafts(_, info):
.options(joinedload(Shout.authors), joinedload(Shout.topics)) .options(joinedload(Shout.authors), joinedload(Shout.topics))
.filter(and_(Shout.deleted_at.is_(None), Shout.created_by == author.id)) .filter(and_(Shout.deleted_at.is_(None), Shout.created_by == author.id))
.filter(Shout.published_at.is_(None)) .filter(Shout.published_at.is_(None))
.order_by(desc(Shout.created_at)) .order_by(desc(coalesce(Shout.updated_at, Shout.created_at)))
.group_by(Shout.id) .group_by(Shout.id)
) )
shouts = [shout for [shout] in session.execute(q).unique()] shouts = [shout for [shout] in session.execute(q).unique()]