def put(self, request, pk, format=None):
        get_instance = None
        try:
            get_instance = self.model.objects.filter(is_deleted=False).get(
                pk=int(pk))
        except self.model.DoesNotExist:
            success = True
            error = list()
            error.append(response_text[603])
            response_data = successResponse(success, error)
            return Response(response_data, status=response_data["code"])

        serializer = self.serializer_class(get_instance, data=request.data)
        if serializer.is_valid():
            instance = serializer.save()
            instance.updated_by = request.user.id
            instance.save()
            success = True
            data = self.get_object_data(instance)
            response_data = successResponse(success, data)
            # return Response(response_data,status=response_data["code"])
        else:
            print(serializer.errors)
            success = False
            error = list()
            error = getSerializer_errors(serializer.errors)
            response_data = errorResponse(success, error)
            # return Response(response_data,status=response_data["code"])

        return Response(response_data, status=response_data["code"])
    def post(self, request, format=None):

        serializer = self.serializer_class(data=request.data)

        if serializer.is_valid():
            instance = serializer.save()
            instance.created_by = request.user.id
            instance.updated_by = request.user.id
            instance.save()

            success = True
            data = self.get_object_data(instance)
            response_data = successResponse(success, data)
            # return Response(response_data,status=response_data["code"])

        else:
            print(serializer.errors)
            success = False
            error = list()
            error.append(response_text[400])
            error = list(serializer.errors)
            error = getSerializer_errors(serializer.errors)
            response_data = errorResponse(success, error)
            # return Response(response_data,status=response_data["code"])

        return Response(response_data, status=response_data["code"])
 def get(self, request):
     token = Token.objects.get(user=request.user)
     token.delete()
     request.user.save()
     success = True
     # data = list()
     # message = api_message['success_logout']
     response_data = successResponse(success)      
     return Response(response_data,status=response_data["code"])
    def post(self, request):
        print("=====> request.data:",request.data)
        serializer_data = self.serializer_class(data=request.data)
        if serializer_data.is_valid():
            # check for existence            
            get_user = user_model.objects.filter(username=request.data.get('email')).first()
            if not get_user:
                success = False
                error=list()
                error.append(api_message['email_not_exist'])
                response_data = errorResponse(success,error) 
            if get_user:   
                if not get_user.is_active:
                    success = False
                    error=list()
                    error.append(api_message['account_deactivated'])
                    response_data = errorResponse(success,error) 

                else:
                    get_user = authenticate(username=request.data.get('email'), password=request.data.get('password'))
                    if get_user:
                        if  False:#get_user.is_deleted:
                       
                            success = False
                            error=list()
                            error.append(api_message['email_not_exist'])
                            response_data = errorResponse(success,error)
                        else:
                            token = Token.objects.get_or_create(user=get_user)[0]
                            # get_user.is_online = True
                            get_user.save()
                            success = True
                            data = get_login_user_dict(request, get_user,token)
                            message = api_message['login_success']
                            response_data = successResponse(success,data,message)

                    else:
                        # Here email is exist bit password is wrong so success is True but code is 400
                        success = False
                        error=list()
                        error.append(api_message['wrong_credentials'])
                        response_data = errorResponse(success,error)
            else:
                success = False
                error=list()
                error.append(api_message['wrong_credentials'])
                response_data = errorResponse(success,error)  
        else:
            # print("serializer_data:",serializer_data.errors)
            success = False
            error=list()
            # error=serializer_data.errors
            # error.append(response_text[400])
            error = getSerializer_errors(serializer_data.errors)
            response_data = errorResponse(success,error)
           
        return Response(response_data , status=response_data.get("code"))
    def get(self, request, format=None):
        objects = self.model.objects.filter(
            is_deleted=False).order_by('-created_date')
        if objects:

            success = True
            data = self.get_object_list(objects)
            response_data = successResponse(success, data)
        else:
            success = True
            error = list()
            error.append(response_text[603])
            code = 200
            response_data = errorResponse(success, error, code)

        return Response(response_data, status=response_data["code"])
 def patch(self, request, pk, format=None):
     instance = None
     try:
         instance = self.model.objects.filter(is_deleted=False,
                                              pk=int(pk)).first()
     except self.model.DoesNotExist:
         success = False
         error = list()
         error.append(response_text[603])
         response_data = errorResponse(success, error)
     if instance:
         instance.is_active = False if instance.is_active else True
         instance.save()
         success = True
         data = {'is_active': instance.is_active}
         response_data = successResponse(success, data)
     return Response(response_data, status=response_data["code"])
    def get(self, request, pk, format=None):
        get_instance = None
        try:
            get_instance = self.model.objects.filter(is_deleted=False).get(
                pk=int(pk))
        except self.model.DoesNotExist:
            success = True
            error = list()
            error.append(response_text[603])
            code = 200
            response_data = errorResponse(success, error, code)

        if get_instance:
            success = True
            data = self.get_object_data(get_instance)
            response_data = successResponse(success, data)
        else:
            success = True
            error = list()
            error.append(response_text[603])
            code = 200
            response_data = errorResponse(success, error, code)

        return Response(response_data, status=response_data["code"])