add role param to list of users in user relation
This commit is contained in:
@@ -20,6 +20,7 @@ from apps.authorization.models import (
|
||||
Page
|
||||
)
|
||||
from apps.core.exceptions import ConflictException
|
||||
from apps.core.mixins.search_mixin import DynamicSearchMixin
|
||||
from apps.core.mixins.soft_delete_mixin import SoftDeleteMixin
|
||||
|
||||
|
||||
@@ -117,14 +118,31 @@ class PermissionViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||
return Response(serializer.data)
|
||||
|
||||
|
||||
class UserRelationViewSet(SoftDeleteMixin, viewsets.ModelViewSet):
|
||||
class UserRelationViewSet(SoftDeleteMixin, viewsets.ModelViewSet, DynamicSearchMixin):
|
||||
""" Crud Operations for User Relations """
|
||||
|
||||
queryset = UserRelations.objects.all()
|
||||
serializer_class = UserRelationSerializer
|
||||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = [
|
||||
'user__username',
|
||||
'user__mobile',
|
||||
'user__phone',
|
||||
'user__national_code',
|
||||
'user__province__name',
|
||||
'user__city__name',
|
||||
'role__name'
|
||||
]
|
||||
|
||||
def list(self, request, *args, **kwargs):
|
||||
queryset = self.filter_queryset(self.get_queryset().order_by('-create_date')) # noqa
|
||||
role_param = self.request.query_params.get('role') # noqa
|
||||
|
||||
if role_param != '':
|
||||
queryset = self.queryset.filter(role_id=int(role_param))
|
||||
else:
|
||||
queryset = self.get_queryset().order_by('-create_date')
|
||||
|
||||
queryset = self.filter_query(queryset) # noqa
|
||||
|
||||
page = self.paginate_queryset(queryset)
|
||||
if page is not None:
|
||||
|
||||
Reference in New Issue
Block a user