Answer the question
In order to leave comments, you need to log in
How to correctly set a condition if an empty QuerySet [] comes?
Good day, help me set the condition, it is necessary for messages to work:
def post(self, request):
form_name = request.POST.get('name')
form_age = request.POST.get('birthday')
filters = []
a = Q()
if form_age and form_name is not None:
a |= Q(name=form_name) | Q(birthday__icontains=form_age)
filters.append(a)
sort = Child.objects.filter(*filters)
print(sort)
if sort is None:
messages.add_message(self.request, settings.ERROR,
'Ребенок не найден, пожалуйста проверьте правильно ли введены данные.')
context = {
'form': form,
'child': sort
}
return render(request, 'kids/turn.html', context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question