from django_filters import FilterSet, MultipleChoiceFilter, CharFilter

from incident.models import Incident


class IncidentFilters(FilterSet):
    """Filters and ordering for Incidents"""

    assets = CharFilter(method='assets_filter')

    def assets_filter(self, queryset, name: str, value: str):
        """filtering by asset ids format sting with `,` example: ?asset=1,2,3"""
        _value = set(value.split(','))
        return queryset.filter(asset__in=_value)

    class Meta:
        model = Incident
        fields = ['asset']
