Open devhusnain opened 2 years ago
I meet this problem, My solution is (: add APIView and inherit it
from rest_framework.views import APIView
...
class DialogsModelList(ListView, APIView):
http_method_names = ['get', ]
paginate_by = getattr(settings, 'DIALOGS_PAGINATION', 20)
def get_queryset(self):
qs = DialogsModel.objects.filter(Q(user1_id=self.request.user.pk) | Q(user2_id=self.request.user.pk)) \
.select_related('user1', 'user2')
return qs.order_by('-created')
def render_to_response(self, context, **response_kwargs):
# TODO: add online status
user_pk = self.request.user.pk
print(self.request.user)
data = [serialize_dialog_model(i, user_pk) for i in context['object_list']]
page: Page = context.pop('page_obj')
paginator: Paginator = context.pop('paginator')
return_data = {
'page': page.number,
'pages': paginator.num_pages,
'data': data
}
return JsonResponse(return_data, **response_kwargs)
Description
I want to use Rest Framework simpleJWT as authentication earlier I was using Django default authentication. Here are views currently I am getting AnonymousUser error, what changes do I need to get a user request from JWT Authenticated user. I want to get a request.user from a jWT Authenticated user. Please help me out.
Here are views