Luke Plant avatar Luke Plant committed 8c58461

Added ability to specify custom class for filter

Comments (0)

Files changed (2)

django_easyfilters/filterset.py

     def setup_filters(self):
         filters = []
         for i, f in enumerate(self.get_fields()):
+            klass = None
             if isinstance(f, basestring):
                 opts = {}
                 field_name = f
             else:
                 opts = f[1]
                 field_name = f[0]
-            klass = self.get_filter_for_field(field_name)
+                if len(f) > 2:
+                    klass = f[2]
+            if klass is None:
+                klass = self.get_filter_for_field(field_name)
             filters.append(klass(field_name, self.model, self.params, **opts))
         return filters
 

django_easyfilters/tests/filterset.py

         self.assertEqual(DateTimeFilter, type(fs.filters[4]))
         self.assertEqual(NumericRangeFilter, type(fs.filters[5]))
 
+    def test_specify_custom_filter(self):
+        class AuthorFilterSet(FilterSet):
+            fields = [
+                ('likes', {}, NumericRangeFilter)
+                ]
+
+        fs = AuthorFilterSet(Author.objects.all(), QueryDict(''))
+        self.assertEqual(NumericRangeFilter, type(fs.filters[0]))
+
 
 class TestFilters(TestCase):
     fixtures = ['django_easyfilters_tests']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.