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

44 lines
1.5 KiB
Python

from django.db import models
from common.fields import ContainerNumberField
from containers.models import Container
# Create your models here.
class Preinfo(models.Model):
container_number = ContainerNumberField(
max_length=11,
)
container_type = models.ForeignKey(
'common.ContainerTypeModel',
on_delete=models.CASCADE,
related_name='preinfo_container_types',
)
line = models.ForeignKey(
'common.LinesModel',
on_delete=models.CASCADE,
related_name='preinfo_lines',
)
created_on = models.DateTimeField(auto_now_add=True)
created_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='preinfo_created_by',
db_column='created_by_id', # Ensure the column name matches your database schema
)
deleted = models.BooleanField(default=False, null=False)
deleted_by = models.ForeignKey(
'accounts.DepotUser',
on_delete=models.CASCADE,
related_name='preinfo_deleted_by',
db_column='deleted_by_id', # Ensure the column name matches your database schema
null=True,
blank=True
)
deleted_on = models.DateTimeField(null=True, blank=True)
received = models.BooleanField(default=False, null=False)
def clean(self):
if Container.objects.filter(number=self.container_number, expedited=False).exists():
raise ValueError(f'Container with number {self.container_number} is at the depot.')