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 def balance(self): return sum(map(lambda x:x.amount,Payment.objects.filter(account=self))) 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)