Repository: carltongibson/django-filter

Issue:
filter_overrides in the Meta are lost
python 3.4
django 1.10.5
django-filters 0.15.3 or 0.15.4

If you move filter_overrides into the Meta it doesn't get pulled into the AutoFilterSet.

We have a setup like this:

```
class MyFilterSet(FilterSet):
    filter_overrides = {
        ...
    }


class MyDjangoFilterBackend(DjangoFilterBackend):
    default_filter_set = MyFilterSet
```

It works. But when adjusting when upgrading (due to deprecation warning) to this:

```
class MyFilterSet(FilterSet):
    class Meta:
        filter_overrides = {
            ...
        }


class MyDjangoFilterBackend(DjangoFilterBackend):
    default_filter_set = MyFilterSet
```

Our filter_overrides are not applied. Debugging it, it's because the filter_overrides are lost when AutoFilterSet is used in DjangoFilterBackend.get_filter_class(). We've worked around it with the following, but obviously this should not be necessary:

```
class MyDjangoFilterBackend(DjangoFilterBackend):
    default_filter_set = MyFilterSet

    def get_filter_class(self, view, queryset=None):
        filterset = super().get_filter_class(view, queryset)
        if filterset and issubclass(filterset, self.default_filter_set):
            filterset.Meta.filter_overrides = (
                self.default_filter_set.Meta.filter_overrides)

        return filterset
```


Discussion:
> ...obviously this should not be necessary

Reminds me of the joke about the math professor: 

> — Obvious it follows...
> — Er..., sir..., is it obvious?
>
> Professor disappears into office, emerges 30 minutes later.
> — Yes, it's obvious.

Meta class inheritance is a tricky topic. In general I'm happy that users are involved in configuring their custom DRF filter backends. But yes, I can see how you might want `get_filter_class` to handle this automatically. 

First step is to narrow this down to a minimal test case. We can think about an adjustment from there. 
c.f. https://github.com/djangonauts/django-rest-framework-gis/pull/117/files#diff-745c1a45c45145b58594c9c47bee0057L86
Something like the following should be sufficient to support Meta class inheritance. Seems reasonable to me. 

```python
    def get_filter_class(self, view, queryset=None):
        ...
        if filter_fields:
            MetaBase = getattr(self.default_filter_set, 'Meta', object)

            class AutoFilterSet(self.default_filter_set):
                class Meta(MetaBase):
                    model = queryset.model
                    fields = filter_fields

            return AutoFilterSet
```

Resolving patch:
diff --git a/django_filters/rest_framework/backends.py b/django_filters/rest_framework/backends.py
--- a/django_filters/rest_framework/backends.py
+++ b/django_filters/rest_framework/backends.py
@@ -35,8 +35,10 @@ def get_filter_class(self, view, queryset=None):
             return filter_class
 
         if filter_fields:
+            MetaBase = getattr(self.default_filter_set, 'Meta', object)
+
             class AutoFilterSet(self.default_filter_set):
-                class Meta:
+                class Meta(MetaBase):
                     model = queryset.model
                     fields = filter_fields
 


Test patch:
diff --git a/tests/rest_framework/test_backends.py b/tests/rest_framework/test_backends.py
--- a/tests/rest_framework/test_backends.py
+++ b/tests/rest_framework/test_backends.py
@@ -3,9 +3,9 @@
 import datetime
 from decimal import Decimal
 from unittest import skipIf
-import warnings
 
 from django.conf.urls import url
+from django.db.models import BooleanField
 from django.test import TestCase
 from django.test.utils import override_settings
 from django.utils.dateparse import parse_date
@@ -486,3 +486,25 @@ class DjangoFilterOrderingView(generics.ListAPIView):
                 {'id': 1, 'date': '2012-10-08', 'text': 'abc'}
             ]
         )
+
+
+class DefaultFilterSetTests(TestCase):
+    def test_default_meta_inheritance(self):
+        # https://github.com/carltongibson/django-filter/issues/663
+
+        class F(FilterSet):
+            class Meta:
+                filter_overrides = {BooleanField: {}}
+
+        class Backend(DjangoFilterBackend):
+            default_filter_set = F
+
+        view = FilterFieldsRootView()
+        backend = Backend()
+
+        filter_class = backend.get_filter_class(view, view.get_queryset())
+        filter_overrides = filter_class._meta.filter_overrides
+
+        # derived filter_class.Meta should inherit from default_filter_set.Meta
+        self.assertIn(BooleanField, filter_overrides)
+        self.assertDictEqual(filter_overrides[BooleanField], {})