Skip to content

Instantly share code, notes, and snippets.

@nkryptic
Created February 16, 2013 02:30
Show Gist options
  • Save nkryptic/4965223 to your computer and use it in GitHub Desktop.
Save nkryptic/4965223 to your computer and use it in GitHub Desktop.
example of how to override a charfilter which will be used for all charfields on a model in a filterset
from django.db import models
from django.contrib.auth.models import User
from django_filters import CharFilter, FilterSet
class ICharFilter(CharFilter):
def __init__(self, *args, **kwargs):
super(ICharFilter, self).__init__(*args, **kwargs)
self.lookup_type = 'icontains'
class MyFilterSet(FilterSet):
filter_overrides = {
models.CharField: {
'filter_class': ICharFilter
}
}
class Meta:
model = User
fields = ('first_name', 'last_name', 'username')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment