# coding=utf-8
import django_filters

from .models import *
from apps.base import clean_datetime_range

class PackageFilter(django_filters.FilterSet):

    class Meta:
        model = Package
        fields = '__all__'

class OrderFilter(django_filters.FilterSet):
    status = django_filters.CharFilter(field_name='status')
    no = django_filters.CharFilter(field_name='no', lookup_expr='icontains')
    tel = django_filters.CharFilter(field_name='create_user__username', lookup_expr='icontains')
    create_time_0 = django_filters.DateTimeFilter(field_name='create_time', lookup_expr='gte')
    create_time_1 = django_filters.DateTimeFilter(field_name='create_time', lookup_expr='lte')

    class Meta:
        model = Order
        fields = '__all__'

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