diff options
Diffstat (limited to 'app/dispatch/models.py')
| -rw-r--r-- | app/dispatch/models.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/app/dispatch/models.py b/app/dispatch/models.py index 13b4e8b..0dd2ac7 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -2,6 +2,8 @@ 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): @@ -20,16 +22,26 @@ class Load(models.Model): 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) - filename = models.CharField(max_length=256) - document = models.FileField(upload_to='paperwork/') + document = models.FileField(upload_to=paperwork_user_directory_path) def __str__(self): return "%s" % self.load @@ -37,5 +49,6 @@ class Paperwork(models.Model): + auditlog.register(Company) auditlog.register(Load) |
