title: how to get filter data between two dates in django
body: <p>I am working on Django project How to get filter data between two dates I mean (from-date and to-date) <strong>mfdate</strong> is a foreign key and coming from another model. how can I do this can anyone help me to solve this problem I have tried multiple time but it is not working</p>
  <p>here is my Code</p>
  <p><strong>models.py</strong></p>
  <pre><code> class ManufacturingYM(models.Model):
       ManufacturingYMID = models.AutoField(primary_key=True)
       ManufacturingDate = models.DateField(auto_now_add=False, blank= True,null=True)
  
       def __str__(self):
           return str(self.ManufacturingDate)
  
    class Car(models.Model):
        CarID = models.AutoField(primary_key=True)
        CarName = models.CharField(max_length=500, blank=True, null=True, verbose_name=&quot;Car Name&quot;)
        mfdate = models.ForeignKey(ManufacturingYM, blank= True,null=True, on_delete=models.DO_NOTHING, verbose_name=&quot;Manufacturing Date&quot;)
  
        def __str__(self):
            return self.CarName
  </code></pre>
  <p><strong>views.py</strong></p>
  <pre><code>   def searchdd(request):
  
        carForm = Car.objects.all()
        fromdate = str(request.POST.get('from_date'))
        todate = str(request.POST.get('to_date')) 
  
        if fromdate:    
            carForm= Car.objects.filter(mfdate=fromdate)    
        if todate:
            carForm= Car.objects.filter(mfdate=todate)
  
        context = {'carForm':carForm} 
        return render(request, 'app/searchdd.html', context)
  </code></pre>
  <p><strong>home.html</strong></p>
  <pre><code>     &lt;form method=&quot;post&quot; id=&quot;indexForm&quot; action=&quot;/searchdd&quot; data-cars-url=&quot;{% url 'ajax_load_cars' %}&quot;&gt;
      {% csrf_token %}
    &lt;div class=&quot;col-md-12&quot;&gt;
      &lt;div class=&quot;row&quot;&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;
          &lt;label for=&quot;&quot; class=&quot;white&quot;&gt;From Year&lt;/label&gt;
          &lt;select name=&quot;from_date&quot; id=&quot;fromdate&quot; class=&quot;dp-list&quot;&gt;
            &lt;option disabled selected=&quot;true&quot; value=&quot;&quot;&gt;--select Year--&lt;/option&gt;
            {% for mfd in manfd %}
            &lt;option value=&quot;{{car.CarID}}&quot;&gt;{{mfd.ManufacturingDate|date:'Y'}}&lt;/option&gt;
            {% endfor %}
          &lt;/select&gt;
        &lt;/div&gt;
        &lt;div class=&quot;col-md-3&quot;&gt;
          &lt;label for=&quot;&quot; class=&quot;white&quot;&gt;To Year&lt;/label&gt;
          &lt;select name=&quot;to_date&quot; id=&quot;todate&quot; class=&quot;dp-list&quot;&gt;
            &lt;option disabled selected=&quot;true&quot; value=&quot;&quot;&gt;--select Year--&lt;/option&gt;
            {% for mfd in manfd %}
            &lt;option value=&quot;{{car.CarID}}&quot;&gt;{{mfd.ManufacturingDate|date:'Y'}}&lt;/option&gt;
            {% endfor %}
          &lt;/select&gt;
        &lt;/div&gt;
        &lt;/div&gt;
        &lt;/div&gt;
  </code></pre>