Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Сделал фильтрацию пользователей по статусу (продавец/посетитель) #1

Merged
merged 1 commit into from
Sep 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
'django.contrib.messages',
'django.contrib.staticfiles',

'rest_framework',
'django_extensions',
'django_filters',

'custom_user.apps.CustomUserConfig',
]
Expand All @@ -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',
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions custom_user/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down
17 changes: 16 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down