#coding=utf-8
import django_filters
from apps.base import clean_datetime_range
from models import Notice


class NoticeFilter(django_filters.FilterSet):
    company = django_filters.CharFilter(name='department__name',lookup_expr='icontains')
    title = django_filters.CharFilter(name='title', lookup_expr='icontains')
    create_time = django_filters.DateTimeFromToRangeFilter(field_name='create_time')

    class Meta:
        model = Notice
        fields = "__all__"

    def __init__(self, data=None, *args, **kwargs):
        data = clean_datetime_range(data, 'create_time')
        super(NoticeFilter, self).__init__(data, *args, **kwargs)