Created
February 16, 2013 02:30
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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