title: How do I filter and display the contents of my table in my django template according to date
body: <p>I have a template that displays users data (date, name, address, contact no) in a tabular format. How do I apply a filter button on this template that takes in the users date and modifies the table to show the entries for that particular date. </p>
  
  <p><strong>Table.html</strong></p>
  
  <pre><code> {% block content %}
  &lt;h1 style="font-size:300%;"&gt;ATTENDANCE TABLE&lt;/h1&gt;&lt;hr /&gt;&lt;br /&gt;
  
  &lt;table&gt;
  &lt;tr&gt;
      &lt;th&gt;DATE&lt;/th&gt;
      &lt;th&gt;NAME&lt;/th&gt;
      &lt;th&gt;SITE&lt;/th&gt;
      &lt;th&gt;TYPE OF LEAVE&lt;/th&gt;
      &lt;th&gt;REASON&lt;/th&gt;
      &lt;th&gt;ARRIVAL&lt;/th&gt;
      &lt;th&gt;TIME IN&lt;/th&gt;
      &lt;th&gt;TIME OUT&lt;/th&gt;
  &lt;/tr&gt;
  {% for topic in topics %}
  &lt;tr&gt; 
      &lt;td&gt;{{ topic.date }}&lt;/td&gt;
      &lt;td&gt;{{ topic.name }}&lt;/td&gt;
      &lt;td&gt;{{ topic.site }}&lt;/td&gt;
      &lt;td&gt;{{ topic.leave_type }}&lt;/td&gt;
      &lt;td&gt;{{ topic.reason }}&lt;/td&gt;
      &lt;td&gt;{{ topic.arrival }}&lt;/td&gt;
      &lt;td&gt;{{ topic.intime }}&lt;/td&gt;
      &lt;td&gt;{{ topic.outtime }}&lt;/td&gt;
  &lt;/tr&gt;
  {% endfor %}
  </code></pre>
  
  <p></p>
  
  <p>Once this table is displayed, I would like to have a filter button that accepts the date and modifies the table to show entries for that entered date. Would I have to create a new view or just play around with the .html file?</p>
  
  <p>I tried using {{variable|date}} filter to no avail .</p>
  
  <p>EDIT:
  Sharing my other files to implement the form- template filter approach.</p>
  
  <p>forms.py</p>
  
  <pre><code>    from django import forms
      from django.forms.fields import DateField, TimeField, DateInput, TimeInput, 
  
  datetime
      from django.contrib.auth.forms import AuthenticationForm
      from django.utils.translation import ugettext_lazy as _
      from django.forms.extras.widgets import SelectDateWidget
      from .lala import SelectTimeWidget 
      import datetime
  
  
  
      from .models import Topic, AppStaff
  
      class TopicForm(forms.ModelForm):
  
      date= forms.DateField(widget=SelectDateWidget, initial=datetime.date.today) 
      name=forms.ModelChoiceField(queryset=AppStaff.objects.values_list('agent',flat=True))
      intime=forms.TimeField(widget= SelectTimeWidget(twelve_hr=True,      required=False,use_seconds=False),required=False)
      outtime=forms.TimeField(widget= SelectTimeWidget(twelve_hr=True, required=False,use_seconds=False),required=False)
      class Meta:
          model = Topic
          #fields = ['site','leave_type','reason','arrival','intime','outtime']
  
      class FilterForm(forms.Form):
      date1= forms.DateField(widget=SelectDateWidget, initial=datetime.date.today) 
  </code></pre>
  
  <p>Views.py</p>
  
  <pre><code>from django.utils import timezone
  from django.shortcuts import render
  from django.http import HttpRequest
  from django.template import RequestContext
  
  from django.http import HttpResponseRedirect
  from django.core.urlresolvers import reverse
  from django.shortcuts import render_to_response
  from .models import Topic, AppStaff 
  from .forms import TopicForm, FilterForm
  import datetime
  
  
  def topics(request):
        """Show all topics."""
        topics = Topic.objects.all()
        context = {'topics': topics}
  
  
  
        return render(request, 'app/topics.html', context)
  
  
  
      def new_topic(request):
      """Add a new topic."""
      if request.method != 'POST':
          # No data submitted; create a blank form.
          form = TopicForm()
      else:
          # POST data submitted; process data.
          form = TopicForm(request.POST)
          if form.is_valid():
              form.save()
              return HttpResponseRedirect(reverse('new_topic'))
  
      context = {'form': form}
      return render(request, 'app/new_topic.html', context)
  
  
  
  
      def filter(request):
  
          form = FilterForm()
  
  
  
          if request.method == "POST":
              f = FilterForm(request.POST)
              if f.is_valid():
  
                  posts = Topic.objects.filter()
                  return HttpResponseRedirect("app/filter.html",{"posts":posts})
          else:
              return render_to_response("app/filter.html",{"form":form} ,           context_instance = RequestContext(request))
  </code></pre>
  
  <p>filter.html</p>
  
  <pre><code>&lt;body&gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;DATE&lt;/th&gt;
          &lt;th&gt;NAME&lt;/th&gt;
          &lt;th&gt;SITE&lt;/th&gt;
          &lt;th&gt;TYPE OF LEAVE&lt;/th&gt;
          &lt;th&gt;REASON&lt;/th&gt;
          &lt;th&gt;ARRIVAL&lt;/th&gt;
          &lt;th&gt;TIME IN&lt;/th&gt;
          &lt;th&gt;TIME OUT&lt;/th&gt;
          &lt;th&gt;COMMENT&lt;/th&gt;
  
      &lt;/tr&gt;
      {% for post in posts %}
  
          &lt;tr&gt;
              &lt;td&gt;{{ post.date }}&lt;/td&gt;
              &lt;td&gt;{{ post.name }}&lt;/td&gt;
              &lt;td&gt;{{ post.site }}&lt;/td&gt;
              &lt;td&gt;{{ post.leave_type }}&lt;/td&gt;
              &lt;td&gt;{{ post.reason }}&lt;/td&gt;
              &lt;td&gt;{{ post.arrival }}&lt;/td&gt;
              &lt;td&gt;{{ post.intime }}&lt;/td&gt;
              &lt;td&gt;{{ post.outtime }}&lt;/td&gt;
              &lt;td&gt;{{ post.comment }}&lt;/td&gt;
          &lt;/tr&gt;
  
  
    {% endfor %}
  
  
  
  
  &lt;/table&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>My FilterForm shows the date field but when I hit submit, it should open filter.html with the filtered list . Im sure I am missing something but have no idea what it really is for weeks now. </p>