some fields validation and model cleaning

This commit is contained in:
2025-08-05 21:38:16 +03:00
parent 06a3b105d3
commit f16ea7c748
130 changed files with 148 additions and 69 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+10 -3
View File
@@ -1,11 +1,13 @@
from django.core.exceptions import ValidationError
from django.db import models
from common.fields import ContainerNumberField
from common.models import LinesModel, ContainerTypeModel
# from payments.models import ContainerTariffPeriod, AdditionalFees
# Create your models here.
class Container(models.Model):
number = models.CharField(max_length=11)
number = ContainerNumberField(max_length=11)
line = models.ForeignKey(
LinesModel,
on_delete=models.CASCADE,
@@ -25,7 +27,7 @@ class Container(models.Model):
receive_vehicle = models.CharField(max_length=100, blank=True, null=True)
damages = models.TextField(blank=True, null=True)
heavy_damaged = models.BooleanField(default=False)
position = models.CharField(max_length=100, blank=True, null=True)
position = models.CharField(max_length=7, blank=True, null=True)
swept = models.BooleanField(default=False)
swept_on = models.DateTimeField(blank=True, null=True)
swept_by = models.ForeignKey(
@@ -67,6 +69,11 @@ class Container(models.Model):
)
expedition_vehicle = models.CharField(max_length=100, blank=True, null=True)
def clean(self):
if Container.objects.filter(number=self.number, expedited=False).exclude(id=self.id).exists():
raise ValidationError(f'Container with number {self.number} already exists in the depot.!')
if self.heavy_damaged and not self.damages.strip():
raise ValidationError('Heavy damaged containers must have damages specified.')
class ContainerHistory(Container):
Binary file not shown.