Home > database >  How to transfer sql query to django orm code which contains &
How to transfer sql query to django orm code which contains &

Time:10-18

For example, how to translate

SELECT id FROM goods WHERE (goods.id & 1) =1

to django orm code

CodePudding user response:

Goods.objects.extra(where=['id & 1 = 1'])

or

Goods.objects.annotate(flag_fiter=F('id').bitand(1)).filter(flag_fiter=1)
  • Related