How to get OTP in django admin panel only?

So i am working on REST API and doing KYC verification of aadhar card. This is my code:

admin.py

 def save_model(self, request, obj, form, change):
        customer_id = obj.customer_id
        customer_object = Customer.objects.get(id=customer_id)
        first_name = customer_object.first_name
        middle_name = customer_object.middle_name
        last_name = customer_object.last_name
        customer_name = first_name + " " + last_name
        date_of_birth = customer_object.date_of_birth
        aadhar_card = obj.aadhar_card

        # Send OTP request
        url = AADHAR_AUTH_URL_OTP_SEND
        header = {
            "Content-Type":"application/json",
            "x-karza-key" : KARZA_TOKEN 
        }
        payload = {
            "aadhaarNo": obj.aadhar_card,
            "consent": "Y"
        }
        result = requests.post(url, data=json.dumps(payload), headers=header, verify=False)
        result_json = result.json()
        request_id = result_json.get('requestId', '')

        # Verify OTP request
        if request_id:
            otp = input("Enter OTP received on registered mobile number: ") # ask the user to input the OTP
            url = AADHAR_AUTH_URL_VERIFIED_OTP
            payload = {
                "aadhaarNo": obj.aadhar_card,
                "consent": "Y",
                "requestId": request_id,
                "otp": otp
            }
            result = requests.post(url, data=json.dumps(payload), headers=header, verify=False)
            result_json = result.json()
            status = result_json.get('result', {}).get('message', '')

        # Save the results to the database
        if change:
            obj = aadhar_card.objects.get(pk=obj.pk)
            obj.aadhar_card = aadhar_card
            obj.aadhar_request_json = json.dumps(payload)
            obj.aadhar_response_json = json.dumps(result_json)
            obj.updated_by = request.user.id
            status_code = result_json.get('statusCode')
            if status_code == 101:
                obj.status = 101 # Verified
            else:
                obj.status = 3 # Not Verified
            obj.save()
        else:
            obj.aadhar_card = aadhar_card
            obj.aadhar_request_json = json.dumps(payload)
            obj.aadhar_response_json = json.dumps(result_json)
            obj.added_by = request.user.id
            status_code = result_json.get('statusCode')
            if status_code == 101:
                obj.status = 101 # Verified
            else:
                obj.status = 3 # Not Verified
            obj.save()
            
        super().save_model(request, obj, form, change)

Now the problem is that i have to enter the OTP in terminal. How can I take otp from the user on DJANGO ADMIN PANEL it self as i am not using any views i have worked on admin.py only.

Any help would be appreciated!

Back to Top