Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. class Expense(models.Model):
  2. pay_from = models.CharField(max_length=200)
  3. payment_option = models.ForeignKey('Ledger', on_delete=models.CASCADE)
  4. amount_to_pay = models.IntegerField(default=0)
  5. expense_date = models.DateField(default=datetime.date.today)
  6. expense_type = models.ForeignKey(ExpenseType, on_delete=models.CASCADE)
  7. note = models.TextField()
  8. created = models.DateTimeField(auto_now_add=True)
  9. updated = models.DateTimeField(auto_now=True)
  10. slug = AutoSlugField(unique_with='id', populate_from='expense_type')
  11.  
  12. def get_amount_to_pay(self):
  13. return self.amount_to_pay
  14.  
  15.  
  16. class Ledger(models.Model):
  17. name = models.CharField(max_length=200)
  18. account_number = models.CharField(max_length=250, unique=True)
  19. account_type = models.CharField(max_length=200)
  20. opening_balance = models.IntegerField(default=0)
  21. amount_to_pay = models.IntegerField(default=0, blank=True, null=True)
  22. current_balance = models.IntegerField(default=0, blank=True, null=True)
  23. created = models.DateTimeField(auto_now_add=True)
  24. updated = models.DateTimeField(auto_now=True)
  25. slug = AutoSlugField(unique_with='id', populate_from='name')
  26.  
  27. def save(self, *args, **kwargs):
  28. self.amount_to_pay = Expense.get_amount_to_pay(self)
  29. #self.amount_to_pay = 10000
  30. # here how can i save the amount_to_pay from expense form if the ledger.id and expense.payment_option.id matches??
  31. #i got stuck here.
  32. self.current_balance = self.opening_balance - self.amount_to_pay
  33.  
  34. super(Ledger, self).save(*args, **kwargs)
  35.  
  36. def save(self, *args, **kwargs):
  37. #self.date_created = timezone.now()
  38. # YOUR LOGIC HERE
  39. super(YOUR_OVERRIDING_MODEL , self).save(*args, **kwargs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement