from django_filters import FilterSet

from antxetamedia.news.models import NewsPodcast
from antxetamedia.radio.models import RadioPodcast
from antxetamedia.projects.models import ProjectShow


# We do not want to accidentally discard anything, so be inclusive and always
# make gte and lte lookups instead of using gt or lt ones


class NewsPodcastFilterSet(FilterSet):
    class Meta:
        model = NewsPodcast
        fields = {
            'show': ['exact'],
            'categories': ['exact'],
            'pub_date': ['gte', 'lte'],
        }


class RadioPodcastFilterSet(FilterSet):
    class Meta:
        model = RadioPodcast
        fields = {
            'show': ['exact'],
            'show__category': ['exact'],
            'show__producer': ['exact'],
            'pub_date': ['gte', 'lte'],
        }


class ProjectShowFilterSet(FilterSet):
    class Meta:
        model = ProjectShow
        fields = {
            'producer': ['exact'],
            'creation_date': ['year__exact'],
        }

from django.utils.translation import ugettext_lazy as _

from django_filters import FilterSet, DateTimeFilter

from antxetamedia.news.models import NewsPodcast
from antxetamedia.radio.models import RadioPodcast
from antxetamedia.projects.models import ProjectShow


# We do not want to accidentally discard anything, so be inclusive and always
# make gte and lte lookups instead of using gt or lt ones


class NewsPodcastFilterSet(FilterSet):
    pub_date_after = DateTimeFilter('pub_date', lookup_type='gte', label=_('Published after'))
    pub_date_before = DateTimeFilter('pub_date', lookup_type='lte', label=_('Published before'))

    class Meta:
        model = NewsPodcast
        fields = ['show', 'categories', 'pub_date_after', 'pub_date_before']


class RadioPodcastFilterSet(FilterSet):
    pub_date_after = DateTimeFilter('pub_date', lookup_type='gte', label=_('Published after'))
    pub_date_before = DateTimeFilter('pub_date', lookup_type='lte', label=_('Published before'))

    class Meta:
        model = RadioPodcast
        fields = ['show', 'show__category', 'show__producer', 'pub_date_after', 'pub_date_before']


class ProjectShowFilterSet(FilterSet):
    class Meta:
        model = ProjectShow
        fields = {
            'producer': ['exact'],
            'creation_date': ['year__exact'],
        }

Add labels to the pub_date__lte pub_date__gte filters
Add labels to the pub_date__lte pub_date__gte filters

+ from django.utils.translation import ugettext_lazy as _
+ 
- from django_filters import FilterSet
+ from django_filters import FilterSet, DateTimeFilter
  
  from antxetamedia.news.models import NewsPodcast
  from antxetamedia.radio.models import RadioPodcast
  from antxetamedia.projects.models import ProjectShow
  
  
  # We do not want to accidentally discard anything, so be inclusive and always
  # make gte and lte lookups instead of using gt or lt ones
  
  
  class NewsPodcastFilterSet(FilterSet):
+     pub_date_after = DateTimeFilter('pub_date', lookup_type='gte', label=_('Published after'))
+     pub_date_before = DateTimeFilter('pub_date', lookup_type='lte', label=_('Published before'))
+ 
      class Meta:
          model = NewsPodcast
+         fields = ['show', 'categories', 'pub_date_after', 'pub_date_before']
-         fields = {
-             'show': ['exact'],
-             'categories': ['exact'],
-             'pub_date': ['gte', 'lte'],
-         }
  
  
  class RadioPodcastFilterSet(FilterSet):
+     pub_date_after = DateTimeFilter('pub_date', lookup_type='gte', label=_('Published after'))
+     pub_date_before = DateTimeFilter('pub_date', lookup_type='lte', label=_('Published before'))
+ 
      class Meta:
          model = RadioPodcast
+         fields = ['show', 'show__category', 'show__producer', 'pub_date_after', 'pub_date_before']
-         fields = {
-             'show': ['exact'],
-             'show__category': ['exact'],
-             'show__producer': ['exact'],
-             'pub_date': ['gte', 'lte'],
-         }
  
  
  class ProjectShowFilterSet(FilterSet):
      class Meta:
          model = ProjectShow
          fields = {
              'producer': ['exact'],
              'creation_date': ['year__exact'],
          }
  
Add labels to the pub_date__lte pub_date__gte filters
## Code Before:
from django_filters import FilterSet

from antxetamedia.news.models import NewsPodcast
from antxetamedia.radio.models import RadioPodcast
from antxetamedia.projects.models import ProjectShow


# We do not want to accidentally discard anything, so be inclusive and always
# make gte and lte lookups instead of using gt or lt ones


class NewsPodcastFilterSet(FilterSet):
    class Meta:
        model = NewsPodcast
        fields = {
            'show': ['exact'],
            'categories': ['exact'],
            'pub_date': ['gte', 'lte'],
        }


class RadioPodcastFilterSet(FilterSet):
    class Meta:
        model = RadioPodcast
        fields = {
            'show': ['exact'],
            'show__category': ['exact'],
            'show__producer': ['exact'],
            'pub_date': ['gte', 'lte'],
        }


class ProjectShowFilterSet(FilterSet):
    class Meta:
        model = ProjectShow
        fields = {
            'producer': ['exact'],
            'creation_date': ['year__exact'],
        }

## Instruction:
Add labels to the pub_date__lte pub_date__gte filters
## Code After:
from django.utils.translation import ugettext_lazy as _

from django_filters import FilterSet, DateTimeFilter

from antxetamedia.news.models import NewsPodcast
from antxetamedia.radio.models import RadioPodcast
from antxetamedia.projects.models import ProjectShow


# We do not want to accidentally discard anything, so be inclusive and always
# make gte and lte lookups instead of using gt or lt ones


class NewsPodcastFilterSet(FilterSet):
    pub_date_after = DateTimeFilter('pub_date', lookup_type='gte', label=_('Published after'))
    pub_date_before = DateTimeFilter('pub_date', lookup_type='lte', label=_('Published before'))

    class Meta:
        model = NewsPodcast
        fields = ['show', 'categories', 'pub_date_after', 'pub_date_before']


class RadioPodcastFilterSet(FilterSet):
    pub_date_after = DateTimeFilter('pub_date', lookup_type='gte', label=_('Published after'))
    pub_date_before = DateTimeFilter('pub_date', lookup_type='lte', label=_('Published before'))

    class Meta:
        model = RadioPodcast
        fields = ['show', 'show__category', 'show__producer', 'pub_date_after', 'pub_date_before']


class ProjectShowFilterSet(FilterSet):
    class Meta:
        model = ProjectShow
        fields = {
            'producer': ['exact'],
            'creation_date': ['year__exact'],
        }
