Add validators
This commit is contained in:
parent
c91994d041
commit
9e7563e38e
4 changed files with 20 additions and 15 deletions
|
@ -1,16 +1,18 @@
|
|||
import uuid
|
||||
from django.db import models
|
||||
from django.forms import ModelForm
|
||||
from django.core.validators import validate_unicode_slug, FileExtensionValidator
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=64)
|
||||
name = models.CharField(max_length=64, validators=[validate_unicode_slug])
|
||||
full_name = models.CharField(max_length=512, editable=False, default="")
|
||||
parent = models.ForeignKey("self", on_delete=models.SET_NULL, blank=True, null=True)
|
||||
|
||||
def __str__(self):
|
||||
if self.parent is None: return self.name
|
||||
if self.parent is None:
|
||||
return self.name
|
||||
return f"{self.parent}>{self.name}"
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
|
@ -20,7 +22,7 @@ class Category(models.Model):
|
|||
child.save()
|
||||
|
||||
class Meta:
|
||||
ordering = ['full_name']
|
||||
ordering = ["full_name"]
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
|
@ -49,7 +51,9 @@ class TransactionForm(ModelForm):
|
|||
class Invoice(models.Model):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(max_length=256)
|
||||
file = models.FileField(upload_to="invoices/")
|
||||
file = models.FileField(
|
||||
upload_to="invoices/", validators=[FileExtensionValidator(["pdf"])]
|
||||
)
|
||||
transaction = models.ForeignKey(Transaction, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue