views.py
and urls.py
in myapp. for filter a list between dates from an input date in a template.This is my models.py
:
class Paciente(models.Model):
tipo_doc = models.ForeignKey(Tipo_doc)
num_doc = models.CharField(max_length=20, primary_key=True)
...
class Consulta (models.Model):
numero = models.ForeignKey(Paciente)
fecha = models.DateField()
...
This is my file "lista.html" in templates:
<h5>
Fecha desde: <input class="inputDate" id="fechadesde" value={{ fecha_d }} />
Fecha hasta: <input class="inputDate" id="fechahasta" value={{ fecha_h }} />
<a href="/clinica/filtrar_consulta" class="button">Filtrar</a>
</h5>
<ul class="actions">
...
I need to filter the list by paciente
and between 2 dates (fecha_d
, fecha_h
), but I don't know how to pass parameters in url. Thank You
from django.conf.urls import patterns, url
from <myapp> import views
urlpatterns = patterns('<myapp>.views',
url(r'^$',views.index, name="index"),
url(r'^listarConsultas/$', views.listarConsultas, name="listarConsultas"),
)
def listarConsultas(request):
if request.method == "POST":
fecha_desde = request.POST["fechadesde"]
fecha_hasta = request.POST["fechahasta"]
...
from django import forms
class pacienteConsultasForm(forms.Form):
fecha_desde = forms.DateField()
fecha_hasta = forms.DateField()
paciente = forms.ModelChoiceField(queryset=Paciente.objects.all())