You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

48 lines
1.8 KiB

from django.core.validators import RegexValidator
from django.db import models
from django.db.models import Q
from .base import TimestampedModel
class Account(TimestampedModel):
class Kind(models.TextChoices):
BANK = "BANK", "Bank"
CREDIT_CARD = "CREDIT_CARD", "Credit card"
name = models.CharField(max_length=255, unique=True)
kind = models.CharField(max_length=16, choices=Kind.choices)
currency = models.CharField(max_length=3, default="BRL", validators=[
RegexValidator(r"\A[A-Z]{3}\Z", "Use three uppercase ASCII letters.")])
archived = models.BooleanField(default=False)
class Meta:
constraints = [
models.CheckConstraint(condition=Q(kind__in=["BANK", "CREDIT_CARD"]), name="account_valid_kind"),
models.CheckConstraint(condition=Q(currency__regex=r"^[A-Z]{3}$"), name="account_valid_currency"),
models.CheckConstraint(condition=Q(name__regex=r"\S"), name="account_nonblank_name"),
]
class Payee(TimestampedModel):
name = models.CharField(max_length=255, unique=True)
archived = models.BooleanField(default=False)
class Meta:
constraints = [models.CheckConstraint(condition=Q(name__regex=r"\S"), name="payee_nonblank_name")]
class Category(TimestampedModel):
class Kind(models.TextChoices):
INCOME = "INCOME", "Income"
EXPENSE = "EXPENSE", "Expense"
name = models.CharField(max_length=255, unique=True)
kind = models.CharField(max_length=16, choices=Kind.choices)
archived = models.BooleanField(default=False)
class Meta:
constraints = [
models.CheckConstraint(condition=Q(kind__in=["INCOME", "EXPENSE"]), name="category_valid_kind"),
models.CheckConstraint(condition=Q(name__regex=r"\S"), name="category_nonblank_name"),
]