async def get_all(
self,
session: AsyncSession,
order_field: str | None = ‘created_at’,
is_desc: bool | None = False,
**param
):
if order_field is not None:
if is_desc:
k = desc(order_field)
else:
k = order_field
else:
k = 'created_at'
objs = await session.scalars(select(self.__model).filter_by(**param).order_by(k))
return objs.all()
I have legacy code that returns all objects from the database.
Im need to change the code, or create a new method to return objects whose registration date is between two datetime dates.
At the moment, I’m just clinging to all the objects and cutting off unsuitable data in the code, but this option is clearly not optimal at all.
In django orm, everything is somehow simple, but here I have scoured the entire Internet and have not found any built-in options in order to implement this.
Thank you in advance for your help <3
Fearzenter is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1