3
Imagine I have a list and a form to filter this list by date.
Does anyone have any example of how to make this filter in the form?
I got this here in the shell, but I don’t know how to implement 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
Then I tried to 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 that.
Would this filtering occur with page reload (i.e. calling the view and rendering the template again) or without reloading (i.e. via Javascript)? Your current code in the view works?
– mgibsonbr