Commits

Luke Plant committed f6b7b11

Use NumericRangeFilter with FloatField

Comments (0)

Files changed (6)

django_easyfilters/filterset.py

             type_ = f.get_internal_type()
             if type_ == 'DateField' or type_ == 'DateTimeField':
                 return DateTimeFilter
-            elif type_ == 'DecimalField':
+            elif type_ == 'DecimalField' or type_ == 'FloatField':
                 return NumericRangeFilter
             else:
                 return ValuesFilter

django_easyfilters/tests/admin.py

 class BookAdmin(admin.ModelAdmin):
     def authors(obj):
         return ", ".join(unicode(a) for a in obj.authors.all())
-    list_display = ["name", authors, "binding", "genre", "price", "date_published", "edition"]
-    list_editable = ["binding", "genre", "price", "date_published", "edition"]
+    list_display = ["name", authors, "binding", "genre", "price", "date_published", "edition", "rating"]
+    list_editable = ["binding", "genre", "price", "date_published", "edition", "rating"]
     list_filter = ["genre", "authors", "binding", "price"]
 
 

django_easyfilters/tests/filterset.py

                 'authors',
                 'date_published',
                 'price',
+                'rating',
                 ]
 
         fs = BookFilterSet(Book.objects.all(), QueryDict(''))
         self.assertEqual(ManyToManyFilter, type(fs.filters[3]))
         self.assertEqual(DateTimeFilter, type(fs.filters[4]))
         self.assertEqual(NumericRangeFilter, type(fs.filters[5]))
+        self.assertEqual(NumericRangeFilter, type(fs.filters[6]))
 
     def test_specify_custom_filter(self):
         class AuthorFilterSet(FilterSet):

django_easyfilters/tests/fixtures/django_easyfilters_tests.json

     "pk": 1, 
     "model": "tests.book", 
     "fields": {
+      "rating": 0.5, 
       "name": "Pride and Prejudice", 
       "edition": 3, 
       "price": "5", 
     "pk": 2, 
     "model": "tests.book", 
     "fields": {
+      "rating": 1.4, 
       "name": "Emma", 
       "edition": 3, 
       "price": "4.99", 
     "pk": 3, 
     "model": "tests.book", 
     "fields": {
+      "rating": 4.3, 
       "name": "Jane Eyre", 
       "edition": 1, 
       "price": "3.5", 
     "pk": 4, 
     "model": "tests.book", 
     "fields": {
+      "rating": 4.2, 
       "name": "Through The Looking Glass", 
       "edition": 1, 
       "price": "10.99", 
     "pk": 5, 
     "model": "tests.book", 
     "fields": {
+      "rating": 0.3, 
       "name": "Winnie-the-Pooh", 
       "edition": 2, 
       "price": "5.99", 
     "pk": 6, 
     "model": "tests.book", 
     "fields": {
+      "rating": 3.4, 
       "name": "Poems", 
       "edition": 1, 
       "price": "4.5", 
     "pk": 7, 
     "model": "tests.book", 
     "fields": {
+      "rating": 4.9, 
       "name": "Wuthering Heights", 
       "edition": 1, 
       "price": "44.99", 
     "pk": 8, 
     "model": "tests.book", 
     "fields": {
+      "rating": 3.7, 
       "name": "Mansfield Park", 
       "edition": 1, 
       "price": "5.5", 
     "pk": 9, 
     "model": "tests.book", 
     "fields": {
+      "rating": 2.0, 
       "name": "The Tenant of Wildfell Hall", 
       "edition": 1, 
       "price": "6", 
     "pk": 10, 
     "model": "tests.book", 
     "fields": {
+      "rating": 1.11, 
       "name": "Shirley", 
       "edition": 1, 
       "price": "4.5", 
     "pk": 11, 
     "model": "tests.book", 
     "fields": {
+      "rating": 1.8, 
       "name": "Sense and Sensibility", 
       "edition": 1, 
       "price": "6.99", 
     "pk": 12, 
     "model": "tests.book", 
     "fields": {
+      "rating": 4.62, 
       "name": "Northanger Abbey", 
       "edition": 1, 
       "price": "4.25", 
     "pk": 13, 
     "model": "tests.book", 
     "fields": {
+      "rating": 3.65, 
       "name": "Persuasion", 
       "edition": 1, 
       "price": "3.8", 
     "pk": 14, 
     "model": "tests.book", 
     "fields": {
+      "rating": 2.5, 
       "name": "Animal Farm", 
       "edition": 1, 
       "price": "6.5", 
     "pk": 15, 
     "model": "tests.book", 
     "fields": {
+      "rating": 0.93, 
       "name": "Great Expectations", 
       "edition": 1, 
       "price": "4.99", 
     "pk": 16, 
     "model": "tests.book", 
     "fields": {
+      "rating": 1.3, 
       "name": "Imperial Earth", 
       "edition": 1, 
       "price": "5.99", 
     "pk": 17, 
     "model": "tests.book", 
     "fields": {
+      "rating": 3.4, 
       "name": "The Professor", 
       "edition": 1, 
       "price": "4.99", 

django_easyfilters/tests/models.py

     price = models.DecimalField(max_digits=6, decimal_places=2)
     date_published = models.DateField()
     edition = models.IntegerField(default=1)
+    rating = models.FloatField(null=True)
 
     def __unicode__(self):
         return self.name

django_easyfilters/tests/views.py

         'genre',
         'price',
         'date_published',
+        'rating',
         ]
 
 def books(request):