The following code searches for values in the template. But it finds by text, and when I type, for example, 2015 to find by year, it returns an error because the field must be an integer and not a number, how to handle this error so that it finds the year? >
p = Proposal.objects.all().select_related()
q = self.request.GET.get('search_box')
if not q in [None, '']:
p = p.filter(
Q(id__icontains=q) |
Q(work__name_work__icontains=q) |
Q(work__customer__first_name__icontains=q) |
Q(category__category__startswith=q) |
Q(employee__user__first_name__startswith=q) |
Q(seller__employee__user__first_name__startswith=q) |
Q(created__year=q)
)
See the error:
ValueError at /proposal/
The __year lookup type requires an integer argument
In the case, when I type one year it works, but when I type another text it gives error.