Possible to do an `in` `lookup_type` through the django-filter URL parser?

后端 未结 7 1277
野性不改
野性不改 2020-12-09 17:52

I\'m using django-filter with django-rest-framework and I\'m trying to instantiate a filter that accepts lists of numbers for filtering the query set down

c         


        
7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 18:46

    According to a post in the django-filter issues:

    from django_filters import Filter
    from django_filters.fields import Lookup
    
    class ListFilter(Filter):
        def filter(self, qs, value):
            return super(ListFilter, self).filter(qs, Lookup(value.split(u","), "in"))
    

    I have personally used this without any issue in my projects, and it works without having to create a per-type filter.

提交回复
热议问题