where = (
    '%(year)s >= YEAR(date_from) AND IF(%(year)s > YEAR(date_from),      IF(%(month)s > MONTH(date_from), %(month)s >= MONTH(date_from), %(month)s < MONTH(date_from)),      IF(%(month)s < MONTH(date_from), %(month)s < MONTH(date_from), %(month)s >= MONTH(date_from)))      AND %(year)s <= YEAR(date_to)      AND %(month)s <= MONTH(date_to)'
     % {'year': year, 'month': month})
Departure_Date.objects.extra(where=[where])
Django, filter by specified month and year in date range