Imagine that I have a list and a form to filter this list by date.
Does anyone have an example of how to do this filter in form?
I got this here in the shell, but I do not know how to implement it in the form, in the template.
$ ./manage.py shell
>>> from core.models import Job
>>> import datetime
>>> start_date=datetime.date(2015,8,1)
>>> end_date=datetime.date(2015,9,1)
>>> q=Job.objects.filter(data_job__range=(start_date,end_date))
>>> for i in q: i.nome_job, i.data_job
I tried it on views.py
p = Job.objects.all()
q = self.request.GET.get('search_box')
# buscar por job
if q is not None:
p = p.filter(nome_job__icontains=q)
# dmin = datetime.date(2015, 8, 1)
dmin = self.request.GET.get('min_date')
dmax = self.request.GET.get('max_date')
p = p.filter(data_job__lte=dmin,data_job__gte=dmax)
I need something like this.