|
| 1 | +from django.core.validators import MaxValueValidator, MinValueValidator |
| 2 | +from django.db import models |
| 3 | +from django.utils.translation import gettext_lazy as _ |
| 4 | +from model_utils.models import TimeStampedModel, UUIDModel |
| 5 | + |
| 6 | +from .constants import AccountTypeChoices |
| 7 | + |
| 8 | + |
| 9 | +class Customer(UUIDModel, TimeStampedModel): |
| 10 | + cust_id = models.PositiveIntegerField(_("9 Digit customer ID")) |
| 11 | + name = models.CharField(_("Customer Name"), max_length=50) |
| 12 | + email = models.EmailField(unique=True) |
| 13 | + |
| 14 | + def __str__(self): |
| 15 | + return f"Customer: [{self.name} - {self.cust_id} - {self.email}]" |
| 16 | + |
| 17 | + |
| 18 | +class AccountType(UUIDModel, TimeStampedModel): |
| 19 | + account_type = models.CharField(_("Type of Account"), unique=True, choices=AccountTypeChoices.choices) |
| 20 | + description = models.TextField(blank=True) |
| 21 | + |
| 22 | + def __str__(self): |
| 23 | + return f"Account Type: [{self.account_type}]" |
| 24 | + |
| 25 | + |
| 26 | +class Account(UUIDModel, TimeStampedModel): |
| 27 | + customer = models.ForeignKey(Customer, on_delete=models.PROTECT) |
| 28 | + account_type = models.ForeignKey(AccountType, on_delete=models.PROTECT) |
| 29 | + account_number = models.PositiveBigIntegerField(_("16 digit account number")) |
| 30 | + balance = models.DecimalField(max_digits=12, decimal_places=2) |
| 31 | + |
| 32 | + def __str__(self): |
| 33 | + return ( |
| 34 | + f"{self.customer.name}({self.customer.cust_id}) - {self.account_type.account_type} " |
| 35 | + f"Account: [{self.account_number}]" |
| 36 | + ) |
0 commit comments