From bb9ea8b1de46733df516c0223a456859f5ea85a6 Mon Sep 17 00:00:00 2001 From: Alexandr Abramov Date: Mon, 25 Sep 2023 01:52:57 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=84?= =?UTF-8?q?=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D1=8E=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=B9=20=D0=BF=D0=BE=20=D1=81=D1=82=D0=B0=D1=82=D1=83?= =?UTF-8?q?=D1=81=D1=83=20(=D0=BF=D1=80=D0=BE=D0=B4=D0=B0=D0=B2=D0=B5?= =?UTF-8?q?=D1=86/=D0=BF=D0=BE=D1=81=D0=B5=D1=82=D0=B8=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/settings.py | 12 +++++++++++- custom_user/views.py | 3 +++ poetry.lock | 17 ++++++++++++++++- pyproject.toml | 1 + 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/config/settings.py b/config/settings.py index 8a8d2ad..a664e98 100644 --- a/config/settings.py +++ b/config/settings.py @@ -41,7 +41,9 @@ 'django.contrib.messages', 'django.contrib.staticfiles', + 'rest_framework', 'django_extensions', + 'django_filters', 'custom_user.apps.CustomUserConfig', ] @@ -56,6 +58,10 @@ # Setting the permission policy # https://www.django-rest-framework.org/api-guide/permissions/#setting-the-permission-policy +# Integration with Django Rest Framework is provided through a DRF-specific FilterSet and a filter backend. +# These may be found in the rest_framework sub-package. +# https://django-filter.readthedocs.io/en/stable/guide/rest_framework.html + REST_FRAMEWORK = { 'DEFAULT_AUTHENTICATION_CLASSES': ( 'rest_framework_simplejwt.authentication.JWTAuthentication', @@ -65,7 +71,11 @@ 'DEFAULT_PERMISSION_CLASSES': [ # 'rest_framework.permissions.IsAuthenticated', 'rest_framework.permissions.AllowAny', - ] + ], + + 'DEFAULT_FILTER_BACKENDS': ( + 'django_filters.rest_framework.DjangoFilterBackend', + ), } # Some of Simple JWT’s behavior can be customized through settings variables in settings.py diff --git a/custom_user/views.py b/custom_user/views.py index 1ede235..be8fc92 100644 --- a/custom_user/views.py +++ b/custom_user/views.py @@ -1,3 +1,4 @@ +from django_filters.rest_framework import DjangoFilterBackend from rest_framework import generics from custom_user.models import CustomUser from custom_user.serializers import CustomUserListSerializer, CustomUserCreateSerializer @@ -8,6 +9,8 @@ class CustomUserListView(generics.ListAPIView): serializer_class = CustomUserListSerializer queryset = CustomUser.objects.all() + filter_backends = [DjangoFilterBackend] + filterset_fields = ('is_seller', ) class CustomUserCreateView(generics.CreateAPIView): diff --git a/poetry.lock b/poetry.lock index e357920..7573c38 100644 --- a/poetry.lock +++ b/poetry.lock @@ -185,6 +185,21 @@ files = [ [package.dependencies] Django = ">=3.2" +[[package]] +name = "django-filter" +version = "23.3" +description = "Django-filter is a reusable Django application for allowing users to filter querysets dynamically." +category = "dev" +optional = false +python-versions = ">=3.7" +files = [ + {file = "django-filter-23.3.tar.gz", hash = "sha256:015fe155582e1805b40629344e4a6cf3cc40450827d294d040b4b8c1749a9fa6"}, + {file = "django_filter-23.3-py3-none-any.whl", hash = "sha256:65bc5d1d8f4fff3aaf74cb5da537b6620e9214fb4b3180f6c560776b1b6dccd0"}, +] + +[package.dependencies] +Django = ">=3.2" + [[package]] name = "djangorestframework" version = "3.14.0" @@ -815,4 +830,4 @@ files = [ [metadata] lock-version = "2.0" python-versions = "^3.9" -content-hash = "50d96cd6fa7d6f56a568c87fc0683e4a0d4d5e45714e4d6c1a4e249bc419e6cc" +content-hash = "acc571445b5030917e35001d2d5e3f2313be19fdb39fb3ca4ba4ec2303b20823" diff --git a/pyproject.toml b/pyproject.toml index ecee01d..99070e6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ coverage = "^7.3.1" flake8 = "^6.1.0" django-extensions = "^3.2.3" ipython = "^8.15.0" +django-filter = "^23.3" [build-system]