How to create a new field in django admin panel inside if condition in a method in the model

In the "save" method, I want to create a new field in the admin panel if the transaction type is transefere and vs code sees the new variable as a deadcode and says it's not accessed.

'''''''''''''''''''''''''''''''''''''''''''''''

    from django.db import models
    import uuid
    import random
    import math

    class Transaction (models.Model):

     customer=models.CharField(max_length=50)
     balance=
     models.DecimalField(
     max_digits=10,decimal_places=2 
     ,default=random.randint (0,30000))
    class trans_options(models.TextChoices):
    CASH_IN= "cash in","cash in"
    CASH_OUT= "cash out" ,"cash out"
    TRANS= "transefere","transefere"
    INVALID="INVALID OPERATION",
    "INVALID OPERATION"
    Transaction_type=models.CharField(
   max_length=50,choices=trans_options.choices
   ,default=trans_options.INVALID)
   amount =models.DecimalField(
   max_digits=4,decimal_places=2)

def save(self, *args, **kwargs):
    if  self.Transaction_type == "cash in" :
    

        self.balance = self.balance + self.amount

    if  self.Transaction_type == "cash out":

      self.balance=self.balance - self.amount 

    if  self.Transaction_type == "transefere" :
        self.balance=self.balance - self.amount
        customer2 = models.CharField(max_length=50) 
        
    return super(Transaction, self).save(*args, **kwargs)'
Back to Top