For filtering by list and using IN operator in django-filters, you can do implement custom filter to do that.

import django_filters

class InListFilter(django_filters.Filter):
    """
    Expected a comma separated list
    filters values in list
    """

    def __init__(self, name=None):
        super().__init__()
        self.name = name

    def filter(self, qs, value):
        if value:
            return qs.filter(**{self.name + '__in': value.split(',')})
        return qs


class MyFilterSet(django_filters.FilterSet):
    status = InListFilter(name='status')

One thought on “Filtering Django REST framework using IN operator or pass list of values”

Leave a Reply