title: Django, filter by specified month and year in date range
body: <p>I have the following models </p>
  
  <pre><code>class Destination_Deal(models.Model):
      name = models.CharField(_("Nombre"),max_length=200)
  
  class Departure_Date(models.Model):
      date_from= models.DateField(_('Desde'))    
      date_to= models.DateField(_('Hasta'))
      destination_deal = models.ForeignKey(Destination_Deal,verbose_name = _("Oferta de Destino"))
  </code></pre>
  
  <p>This is the actual data in the table departure_date</p>
  
  <pre><code>id  date_from   date_to     destination_deal_id
  1   2012-11-01  2013-03-17  1
  2   2012-11-01  2012-12-16  2
  3   2012-09-16  2012-10-31  3
  4   2012-11-01  2012-12-16  3
  5   2013-01-04  2013-01-11  4
  </code></pre>
  
  <p>I would like to filter the Destination_Deals if a specified month&amp;year is between date_from and date_to.</p>
  
  <p><strong>Example 1</strong></p>
  
  <blockquote>
    <p>Month: September (09)<br>
    Year: 2012<br></p>
  </blockquote>
  
  <p><strong>Wanted departure dates result:</strong><br>
  ID 3 : It is the only data range that touch 09/2012 </p>
  
  <p><strong>Example 2</strong></p>
  
  <blockquote>
    <p>Month: February (02)<br>
    Year: 2013<br></p>
  </blockquote>
  
  <p><strong>Wanted departure dates result:</strong><br>
  ID 1 : 02/2012 is before 03/2012<br></p>
  
  <p>So, the day actually is does not matter. If the month&amp;year is between date_from and date_to, even if it is by one day it must be filter.</p>
  
  <p>I think I must use something like <a href="https://stackoverflow.com/questions/1664636/django-date-filter-by-day-of-month?answertab=votes#tab-top">this</a> but I am not sure how to do it.</p>
  
  <p>Thanks in advance!
  Miguel</p>
  
  <p><strong>---Edit---</strong><br/>
  This is the test for the answer from Aamir Adnan but it is not working as I expected as ID 1 must be also returned because it goes from November 2012 to March 2013, so January 2013 is between.<br/></p>
  
  <pre><code>Departure_Date.objects.all()
  [&lt;Departure_Date: id: 1 - from: 2012-11-01 - to: 2013-03-17&gt;,
  &lt;Departure_Date: id: 2 - from: 2012-11-01 - to: 2012-12-16&gt;,
  &lt;Departure_Date: id: 3 - from: 2012-09-16 - to: 2012-10-31&gt;,
  &lt;Departure_Date: id: 4 - from: 2012-11-01 - to: 2012-12-16&gt;,
  &lt;Departure_Date: id: 5 - from: 2013-01-04 - to: 2013-01-11&gt;]
  
  
  month:1
  year:2013
  where = '%(year)s &gt;= YEAR(date_from) AND %(month)s &gt;= MONTH(date_from) \
      AND %(year)s &lt;= YEAR(date_to) AND %(month)s &lt;= MONTH(date_to)' % \
      {'year': year, 'month': month}
  Departure_Date.objects.extra(where=[where])
  [&lt;Departure_Date: id: 5 - from: 2013-01-04 - to: 2013-01-11&gt;]
  </code></pre>