Filters

class cruditor.filters.AnyChoiceFilter(*args, **kwargs)[source]

Bases: ChoiceFilter

Extended ChoiceFilter which adds an “any” choice to the choices from the field / provided options by setting a empty_label on the generated form field.

class cruditor.filters.MultiCharFilter(fields, *args, **kwargs)[source]

Bases: CharFilter

This filter performs an OR query on the defined fields from a single entered value.

The following will work similar to the default UserAdmin search:

class UserFilterSet(FilterSet):
    search = MultiCharFilter([
        'username', 'first_name', 'last_name', '^email'])

    class Meta:
        model = User
        fields = ['search']

The filter supports filtering in different modes (icontains, istartswith, iexact, and search). icontains is the default mode, use ^, = and @ in the list of fields for the other modes.

Based on some ideas from https://gist.github.com/nkryptic/4727865

default_lookup_type = 'icontains'[source]
lookup_types = [('^', 'istartswith'), ('=', 'iexact'), ('@', 'search')][source]
filter(qs, value)[source]