I am working on login api, when i tried to run this command
user_profile = UserProfile.objects.filter(user_id=user.id).values('usertype')
It gives me this error : AttributeError: 'QuerySet' object has no attribute 'usertype' but in console i checked i am getting its queryset <QuerySet [{'usertype': 2}]> but not able to fetch the value from it, can anyone please help me how to resolve this issue ? here is my signin function of it
class Login(APIView):
permission_classes = (AllowAny,)
def post(self, request):
username = request.data.get("username")
password = request.data.get("password")
if username is None or password is None:
return Response({'success': False, 'error': 'Please provide both username and password'},
status=HTTP_400_BAD_REQUEST)
user = authenticate(username=username, password=password)
# return Response({'success': True, 'user': user},status=HTTP_200_OK)
if not user:
return Response({'success': False, 'error': 'Invalid Credentials'},
status=HTTP_400_BAD_REQUEST)
access_token, refresh_token = utils.generate_tokens(user)
user_profile = UserProfile.objects.filter(user_id=user.id).values('usertype')
print(user_profile.usertype)