def _year_month_filter(threads, year=None, month=None):
    """
    Filter a queryset containing a 'postdate' field by year/month.
    """
    if month is not None and not 1 <= month <= 12:
        return None

    if year is not None:
        threads = threads.filter(postdate__year = year)
        # nested since there has to be a year to filter by month
        if month is not None:
            threads = threads.filter(postdate__month = month)

    return threads