Answer the question
In order to leave comments, you need to log in
Queryset q object how to write correctly?
f_name = request.GET.get('fname')
l_name = request.GET.get('lname')
e_mail = request.GET.get('email')
if f_name:
qs = qs.filter(Q(first_name=f_name))
if l_name:
qs = qs.filter(Q(last_name=l_name))
if e_mail:
qs = qs.filter(Q(email=e_mail))
result = '<br>'.join(
str(teacher)
for teacher in qs
)
# return HttpResponse(result)
return render(
request=request,
template_name='teachers_list.html',
context={'teachers_list': result}
)
Answer the question
In order to leave comments, you need to log in
q = Q()
if f_name:
q &= Q(first_name=f_name)
if l_name:
q &= Q(last_name=l_name)
if e_mail:
q &= Q(email=e_mail)
qs = qs.filter(q)
result = '<br>'.join(
str(teacher)
for teacher in qs
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question