title: Filter date by month DRF
body: <p>I want to filter a model that I've created by month &amp; year.</p>
  
  <p>This is my model:</p>
  
  <pre><code>class Cotisation(models.Model):
      date = models.DateTimeField()
      campagne = models.ForeignKey(Campagne, on_delete=models.CASCADE)
  
      class Meta:
          managed = True
          db_table = 'cotisations'
          ordering = ['-id']
  </code></pre>
  
  <p>This is my view: </p>
  
  <pre><code>class CotisationViewSet(viewsets.ModelViewSet):
      queryset = Cotisation.objects.all()
      serializer_class = CotisationSerializer
      pagination_class = StandardResultsSetPagination
      filter_backends = (filters.SearchFilter, DjangoFilterBackend, filters.OrderingFilter,)
      filter_class = CotisationFilter
      search_fields = ('organism__name', 'organism__num_onic')
      ordering_fields = ('date',)
  </code></pre>
  
  <p>And this is my filter class:</p>
  
  <pre><code> class CotisationFilter(django_filters.FilterSet):
       month = django_filters.NumberFilter(field_name='date', lookup_expr='month')
       year = django_filters.NumberFilter(field_name='date', lookup_expr='year')
  
       class Meta:
           model = Cotisation
           fields = ['organism__id', 'campaign__id', 'campaign__year', 'month', 'year']
  </code></pre>
  
  <p>When I try to query by year it works well:</p>
  
  <pre><code>GET http://{{URL}}/cotisations/?year=2019
  </code></pre>
  
  <p>But it doesn't work when I try with month:</p>
  
  <pre><code>GET http://{{URL}}/cotisations/?month=10
  </code></pre>
  
  <p>Thank you in advance.</p>
  
  <p>Best,
  Jeremy.</p>
  
  <p>PS: And Happy new year!</p>
  
  <p><strong><em>SOLUTION:</em></strong></p>
  
  <p><a href="https://stackoverflow.com/a/54055959/5488750">@Horion</a> answered perfectly. </p>
  
  <p>Here is the answer that solved the issue: <a href="https://stackoverflow.com/a/37566565/5488750">Answer</a></p>