title: django search DateTime in between two dates from database
body: <p>I am trying to search and list in between two dates from database ,,but do not know how to do it??
  the </p>
  
  <blockquote>
    <p>models.py</p>
  </blockquote>
  
  <pre><code>...
  class ProductsTbl(models.Model):
      created = models.DateTimeField(editable=False)
  ...
  </code></pre>
  
  <blockquote>
    <p>views.py</p>
  </blockquote>
  
  <pre><code>def search(request):
      error = False
      if 'q1' and 'q2'in request.GET:
          q = request.GET['q1','q2']
          if not q:
              error = True
          else:
              books = ProductsTbl.objects.filter(created__range=q)
              return render(request, 'search_results.html',
                  {'books': books, 'query': q})
      return render(request, 'search_form.html', {'error': error})
  </code></pre>
  
  <p>I have look up <a href="https://stackoverflow.com/a/3963247/5678590">stackoverflow here</a> but do not understand how to do it</p>
  
  <p>shoud I add one more DateTimeField in models.py to help search??</p>
  
  <p>actually I can do it in python manage.py shell, but how can I make it works on the web??
  <a href="https://i.stack.imgur.com/1VfMu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1VfMu.png" alt="enter image description here"></a></p>
  
  <p>my </p>
  
  <blockquote>
    <p>search_form.html</p>
  </blockquote>
  
  <pre><code>&lt;form action="" method="get"&gt;
  &lt;table style="width:30%"&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;input type="text"  class="datepicker" name="q1"&gt; &lt;/td&gt;
  &lt;td style="width:5%"&gt; between &lt;/td&gt;
  &lt;td&gt;&lt;input type="text"  class="datepicker" name="q2"&gt;&lt;/td&gt;
  &lt;br&gt;
  &lt;td&gt;&lt;input type="submit" value="Search"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>the </p>
  
  <blockquote>
    <p>search_results.html</p>
  </blockquote>
  
  <pre><code>{% if books %}
  &lt;p&gt;Found {{ books|length }} product{{ books|pluralize }}.&lt;/p&gt;
  &lt;ul&gt;
  {% for book in books %}
  &lt;li&gt;{{ book.created }}&lt;/li&gt;
  &lt;h2&gt;&lt;a href="{% url 'thing_detail' slug=book.slug %}"&gt;{{ book.name }}&lt;/a&gt;&lt;/h2&gt;
  {% endfor %}
  &lt;/ul&gt;
  {% else %}
  &lt;p&gt;No products matched your search criteria.&lt;/p&gt;
  {% endif %}
  </code></pre>
  
  <p>if only filter for one date it is ok for me to use this </p>
  
  <blockquote>
    <p>views.py</p>
  </blockquote>
  
  <pre><code>def publish(request):
      error = False
      if 'q' in request.GET:
          q = request.GET['q']
          if not q:
              error = True
          else:
              books = ProductsTbl.objects.filter(release__icontains=q)
              return render(request, 'publish_results.html',
                  {'books': books, 'query': q})
      return render(request, 'publish_form.html', {'error': error})
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/k5VxT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/k5VxT.png" alt="enter image description here"></a></p>
  
  <p>however ,,,when comes between two dates range,,,I do not know how to do it</p>