from django.db import models from django.conf import settings from auditlog.registry import auditlog import uuid # Create your models here. class Company(models.Model): name = models.CharField(max_length=256) address = models.CharField(max_length=256) phone_number = models.DecimalField(max_digits=16,decimal_places=0) email_address = models.CharField(max_length=256) contact_name = models.CharField(max_length=256) def __str__(self): return self.name class Load(models.Model): load_number = models.CharField(max_length=64,default="") date = models.DateField() user = models.ForeignKey(settings.AUTH_USER_MODEL) company = models.ForeignKey(Company) description = models.CharField(max_length=256) delivered_to = models.CharField(max_length=256, default="") amount = models.DecimalField(max_digits=10,decimal_places=2, default="0") def __str__(self): return "{c}, {d} ( {a} )".format(c=self.company, d=self.description, a=self.amount) # This is used to set the upload path of the document for Paperwork Objects def paperwork_user_directory_path(instance, filename): # We don't want the UUID to be too long, just enough so there aren't any # filename conflicts return 'paperwork/{:d}/'.format(instance.load.pk) + \ str(uuid.uuid4())[0:9] + filename class Paperwork(models.Model): load = models.ForeignKey(Load, on_delete=models.CASCADE) description = models.CharField(max_length=256) document = models.FileField(upload_to=paperwork_user_directory_path) def __str__(self): return "%s" % self.load auditlog.register(Company) auditlog.register(Load)