How to substract amount input from current balance to get available balance in python Django

Viewed 20

I have available balance field and current balance field in my user profile model in Django. I want to substract amount input from current balance to get available balance show in my web page of the user profile

1 Answers

you can add save() function in your UserProfile model

example:

def save(self, *args, **kwargs):
    self.available_balance = (self.current_balance - self.amount_input)
    return super().save(*args, **kwargs)

You can add more information like the model code to get the concise answer. Hope that one helped let me know.

Related