Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Expense(models.Model):
- pay_from = models.CharField(max_length=200)
- payment_option = models.ForeignKey('Ledger', on_delete=models.CASCADE)
- amount_to_pay = models.IntegerField(default=0)
- expense_date = models.DateField(default=datetime.date.today)
- expense_type = models.ForeignKey(ExpenseType, on_delete=models.CASCADE)
- note = models.TextField()
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(auto_now=True)
- slug = AutoSlugField(unique_with='id', populate_from='expense_type')
- def get_amount_to_pay(self):
- return self.amount_to_pay
- class Ledger(models.Model):
- name = models.CharField(max_length=200)
- account_number = models.CharField(max_length=250, unique=True)
- account_type = models.CharField(max_length=200)
- opening_balance = models.IntegerField(default=0)
- amount_to_pay = models.IntegerField(default=0, blank=True, null=True)
- current_balance = models.IntegerField(default=0, blank=True, null=True)
- created = models.DateTimeField(auto_now_add=True)
- updated = models.DateTimeField(auto_now=True)
- slug = AutoSlugField(unique_with='id', populate_from='name')
- def save(self, *args, **kwargs):
- self.amount_to_pay = Expense.get_amount_to_pay(self)
- #self.amount_to_pay = 10000
- # here how can i save the amount_to_pay from expense form if the ledger.id and expense.payment_option.id matches??
- #i got stuck here.
- self.current_balance = self.opening_balance - self.amount_to_pay
- super(Ledger, self).save(*args, **kwargs)
- def save(self, *args, **kwargs):
- #self.date_created = timezone.now()
- # YOUR LOGIC HERE
- super(YOUR_OVERRIDING_MODEL , self).save(*args, **kwargs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement