How to filter by date part in tortoise ORM

Viewed 1409

I just started using tortoise ORM. And was wondering is it all possible to filter the datetime field by its part. For example to filter out only rows which datetime column corresponds to a given month. Similarly as it is done in Django ORM that is .filter(datetime_field__month=6)

2 Answers

When you use Tortoise ORM and specify that a field is a DatetimeField, you can access its parts, as for example the month, with datetime_field__month.

This only works with PostgreSQL and MySQL, not with SQLite.

You can find the different parts to which you can access here: https://tortoise-orm.readthedocs.io/en/latest/query.html#filtering

Related