How to convert sql mod to django orm?

Viewed 161

The sql is:

select id from tableA where MOD(id,10)=1

database is mysql. How to covert this sql to django orm filter?

1 Answers

You can make use of the % operator:

from django.db.models import F

MyModel.objects.annotate(
    id10=F('id') % 10
).filter(
    id10=1
)
Related