# coding=utf-8

import django_filters
from .models import RepairOrder


class RepairOrderFilter(django_filters.FilterSet):
    no = django_filters.CharFilter(field_name='no', lookup_expr='icontains')
    status = django_filters.CharFilter(method='query_status')
    device_name = django_filters.CharFilter(field_name='device__name', lookup_expr='icontains')

    class Meta:
        model = RepairOrder
        fields = '__all__'

    def query_status(self, queryset, *args):
        queryset = queryset.filter(status__in=args[1].split(','))
        return queryset
