1
Is it possible to write something like??:
sites = Site.objects.filter(category=category or category1=category, is_active=True)
Yes, use the Q
object when you want to use or
:
If you need to execute more complex queries (for example, queries with
OR
statements), you can useQ
objects.A
Q
object (django.db.models.Q
) is an object used to encapsulate a collection of keyword arguments. These keyword arguments are specified as in โField lookupsโ above.
from django.db.models import Q
sites = Site.objects.filter(
Q(category=category) | Q(category1=category),
is_active=True)
Source:stackexchange.com