On Jan 12, 9:29 pm, Ryan Nowakowski <[email protected]> wrote: > I have a model that has an IntegerField. I'd like to filter only the > even integers. sqlite has a modulus operator so I can do: > > select * from mytable where my_int = my_int % 2
Er, that doesn't give you even integers, it gives you rows where my_int is equal to the remainder when my_int is divided by 2 (see http://www.sqlite.org/lang_expr.html) In other words, it will only ever return rows where my_int = 1. I suspect you mean 'where my_int % 2 = 0'. > However, I'd like to use the QuerySet API to do this instead of > resorting to SQL. Any ideas or hints? > > Thanks, > > Ryan You can use the extra() method: MyTable.objects.extra(where=['my_int % 2 = 0']) -- DR.
-- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

