user filter
This commit is contained in:
parent
b45ed4656d
commit
193c245c0a
4 changed files with 33 additions and 1 deletions
|
|
@ -113,7 +113,7 @@ REST_FRAMEWORK = {
|
||||||
'DEFAULT_PERMISSION_CLASSES': (
|
'DEFAULT_PERMISSION_CLASSES': (
|
||||||
'rest_framework.permissions.IsAuthenticated',
|
'rest_framework.permissions.IsAuthenticated',
|
||||||
),
|
),
|
||||||
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
|
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
|
||||||
'PAGE_SIZE': PAGE_SIZE,
|
'PAGE_SIZE': PAGE_SIZE,
|
||||||
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
"DEFAULT_SCHEMA_CLASS": "drf_spectacular.openapi.AutoSchema",
|
||||||
# 'DEFAULT_THROTTLE_CLASSES': [
|
# 'DEFAULT_THROTTLE_CLASSES': [
|
||||||
|
|
|
||||||
12
apps/users/filters.py
Normal file
12
apps/users/filters.py
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
import django_filters
|
||||||
|
from .models import User
|
||||||
|
|
||||||
|
|
||||||
|
class UserFilter(django_filters.FilterSet):
|
||||||
|
class Meta:
|
||||||
|
model = User
|
||||||
|
fields = {
|
||||||
|
'uuid': ['in'],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -7,6 +7,7 @@ from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
from django.views.generic import DetailView, UpdateView
|
from django.views.generic import DetailView, UpdateView
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope
|
from oauth2_provider.contrib.rest_framework import IsAuthenticatedOrTokenHasScope
|
||||||
from rest_framework import generics, status, permissions
|
from rest_framework import generics, status, permissions
|
||||||
from rest_framework.permissions import AllowAny
|
from rest_framework.permissions import AllowAny
|
||||||
|
|
@ -14,6 +15,7 @@ from rest_framework.response import Response
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
from apps.gooyal_oauth2.rest_framework import IsAuthenticatedOrTokenMatchesOASRequirements
|
||||||
|
from apps.users.filters import UserFilter
|
||||||
from apps.users.forms import OTPAuthenticationForm, ProfileUpdateForm
|
from apps.users.forms import OTPAuthenticationForm, ProfileUpdateForm
|
||||||
from apps.users.models import User
|
from apps.users.models import User
|
||||||
from apps.users.provinces_and_cities import State
|
from apps.users.provinces_and_cities import State
|
||||||
|
|
@ -28,6 +30,9 @@ class UserListView(generics.ListAPIView):
|
||||||
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
permission_classes = [IsAuthenticatedOrTokenMatchesOASRequirements]
|
||||||
queryset = User.objects.all()
|
queryset = User.objects.all()
|
||||||
serializer_class = PublicUserSerializer
|
serializer_class = PublicUserSerializer
|
||||||
|
filter_backends = (DjangoFilterBackend,)
|
||||||
|
filterset_class = UserFilter
|
||||||
|
|
||||||
required_alternate_scopes = {
|
required_alternate_scopes = {
|
||||||
"GET": [["accounts.profile:list"]],
|
"GET": [["accounts.profile:list"]],
|
||||||
}
|
}
|
||||||
|
|
|
||||||
15
utils/models.py
Normal file
15
utils/models.py
Normal file
|
|
@ -0,0 +1,15 @@
|
||||||
|
import json
|
||||||
|
import uuid
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
|
||||||
|
class BaseModel(models.Model):
|
||||||
|
id = None
|
||||||
|
uuid = models.UUIDField(primary_key=True, editable=True, default=uuid.uuid4, unique=True, db_index=True)
|
||||||
|
created_at = models.DateTimeField(auto_now_add=True, db_index=True)
|
||||||
|
updated_at = models.DateTimeField(auto_now=True, db_index=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
Loading…
Add table
Reference in a new issue