Reduce db queries in Django view
looks like its doing 3 queries, how can I simplify it so that it makes only 1 db query?
employee = Employee.objects.get(email=self.request.user.email)
filter_args = Q(internal=False)
if ProjectPM.objects.filter(user=employee):
filter_args = Q(projectpm=None) | Q(
projectpm__user=employee,
projectpm__start_date__lte=today,
projectpm__end_date__gte=today,
)
elif ProjectSales.objects.filter(user=employee):
filter_args = Q(projectsales=None) | Q(
projectsales__user=employee,
projectsales__start_date__lte=today,
projectsales__end_date__gte=today,
)
if filter_args:
qs = qs.filter(filter_args)