Skip to content

Commit

Permalink
feat: config django filter backends and filters
Browse files Browse the repository at this point in the history
  • Loading branch information
moonlitgrace committed Nov 14, 2024
1 parent 17847c4 commit c7cf50b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/backend/apps/user/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.contrib.auth import login

from rest_framework import viewsets, permissions
from rest_framework import viewsets, permissions, filters
from rest_framework.decorators import action
from rest_framework.response import Response

Expand Down Expand Up @@ -43,6 +43,9 @@ class ProfileViewSet(viewsets.ModelViewSet):

queryset = Profile.objects.all()
serializer_class = ProfileSerializer
filter_backends = (filters.SearchFilter,)
filterset_fields = ('username', 'user__email')
search_fields = ('username', 'user__email')


class LoginView(KnoxLoginView):
Expand Down
5 changes: 5 additions & 0 deletions backend/backend/core/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
'django_extensions',
# rest framework
'rest_framework',
# django filtering
'django_filters',
# drf token auth
'knox',
# middleware (cors)
Expand All @@ -65,6 +67,9 @@
'DEFAULT_AUTHENTICATION_CLASSES': [
'knox.auth.TokenAuthentication',
],
'DEFAULT_FILTER_BACKENDS': [
'django_filters.rest_framework.DjangoFilterBackend',
],
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.QueryParameterVersioning',
'DEFAULT_VERSION': '1.0.0',
# 'VERSION_PARAM': 'v',
Expand Down
1 change: 1 addition & 0 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ django-cleanup = "^9.0.0"
# rest framework and plugins
djangorestframework = "^3.15.2"
markdown = "^3.7"
# 3rd party (django filtering)
django-filter = "^24.3"
# 3rd party (cors headers)
django-cors-headers = "^4.6.0"
Expand Down

0 comments on commit c7cf50b

Please sign in to comment.