0

I'm not asking on how to do a raw sql. I'm thinking more in terms of the django queryset api. If I want to execute a sql like

select * from table where id="1" or id="2" or id="3";

how would I do it using django queryset api? I know that if you chain filters together you can get AND. But how would you do OR?

BTW how efficient is the queryset api compared to raw sql, generally the same?

Derek
  • 11,980
  • 26
  • 103
  • 162

1 Answers1

2

Your query is the same as select * from table where id in ('1', '2', '3'); which using Django queryset will be: YourModel.objects.filter(id__in=['1', '3', '4']).

mouad
  • 67,571
  • 18
  • 114
  • 106