# coding=utf-8

import django_filters

from .models import BizLog

from utils.format import clean_datetime_range


class BizLogFilter(django_filters.FilterSet):
    type = django_filters.ChoiceFilter(choices=BizLog.TYPE_CHOICES, field_name='type')
    create_time = django_filters.DateTimeFromToRangeFilter(field_name='create_time')

    class Meta:
        model = BizLog
        fields = ('create_time', 'type', )

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