0

I have one sql query:

select * from sample_table where (istatus = 1 AND ((iCategory = 2 and iType=1) or (iType in (2,3,5)));

How can I write the same in Django ORM using filter?

khelwood
  • 55,782
  • 14
  • 81
  • 108
  • Does this answer your question? [How to combine multiple QuerySets in Django?](https://stackoverflow.com/questions/431628/how-to-combine-multiple-querysets-in-django) – sahasrara62 May 16 '23 at 11:47

1 Answers1

0

You can try like this using Q for complex queries:

from django.db.models import Q

SampleModel.objects.filter(
    Q(istatus=1),
    Q(i_category=2, i_type=1) | Q(i_type__in=[2,3,5])
)
ruddra
  • 50,746
  • 7
  • 78
  • 101