1
The following code does a value search in the template. But it locates by text, and when I type, for example, 2015 to locate by year, it returns an error because the field must be an integer and not a number, how to treat this error for it to locate by 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 case, when I type a year it works, but when I type another text gives error.