2022-05-27 03:49:34 +10:00
|
|
|
from django.db import models
|
|
|
|
from django.utils.timezone import now
|
|
|
|
|
|
|
|
# Create your models here.
|
|
|
|
class BankAccount(models.Model):
|
|
|
|
name=models.CharField(max_length=100)
|
|
|
|
physical=models.CharField(max_length=100)
|
|
|
|
currency=models.CharField(max_length=5)
|
|
|
|
@property
|
2022-05-28 23:25:59 +10:00
|
|
|
def balance(self): return sum(map(lambda x:x.amount,Payment.objects.filter(account=self)))
|
2022-05-27 03:49:34 +10:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.name)+', '+str(self.balance)
|
|
|
|
|
|
|
|
class Payment(models.Model):
|
|
|
|
timestamp=models.DateTimeField(default=now)
|
|
|
|
other_party=models.CharField(max_length=100)
|
|
|
|
account=models.ForeignKey(BankAccount, on_delete=models.CASCADE)
|
|
|
|
amount=models.IntegerField(default=0)
|
|
|
|
reason=models.CharField(max_length=200)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.timestamp)+', '+str(self.amount)+', '+str(self.reason)
|
|
|
|
|
|
|
|
class OffDate(models.Model):
|
|
|
|
when=models.DateField(default=now)
|
|
|
|
reason=models.CharField(max_length=50,default="Hall unavailable")
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(str.when)+': '+str(self.reason)
|