Use a class filter to allow expansion
-import django_filters.rest_framework
+import django_filters.rest_framework as filters
from rest_framework.authentication import SessionAuthentication, TokenAuthentication
from rest_framework.permissions import IsAuthenticated
from rest_framework.renderers import JSONRenderer
@@ -8,6 +8,7 @@ from rest_flex_fields import FlexFieldsModelViewSet
from readthedocs.projects.models import Project
from readthedocs.restapi.permissions import IsOwner
+from .filters import ProjectFilter
from .serializers import ProjectSerializer
@@ -17,7 +18,7 @@ class APIv3Settings:
permission_classes = (IsAuthenticated, IsOwner)
renderer_classes = (JSONRenderer,)
throttle_classes = (UserRateThrottle, AnonRateThrottle)
- filter_backends = (django_filters.rest_framework.DjangoFilterBackend,)
+ filter_backends = (filters.DjangoFilterBackend,)
class ProjectsViewSet(APIv3Settings, FlexFieldsModelViewSet):
@@ -26,10 +27,7 @@ class ProjectsViewSet(APIv3Settings, FlexFieldsModelViewSet):
lookup_field = 'slug'
lookup_url_kwarg = 'project_slug'
serializer_class = ProjectSerializer
- filterset_fields = (
- 'slug',
- 'privacy_level',
- )
+ filterset_class = ProjectFilter
permit_list_expands = [
'users',
'active_versions',
