2024-12-26 14:42:24 +02:00

9 lines
319 B
Python

from tortoise.queryset import QuerySet
from service.constants.types import PaginationParams
def order_queryset(qs: QuerySet, filters: PaginationParams, default: str) -> QuerySet:
ordering = [f for f in filters.order.split(",") if f.split("-")[-1] in qs.fields]
return qs.order_by(*(ordering or (default, )))