From 5b2f6041e739be4810709ca49d0538279d3f549d Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Wed, 18 Oct 2017 15:55:23 -0400 Subject: Added a delivered to field. File uploads work. Load detail view works properly now. File upload names are properly set. You can now delete uploaded files --- app/dispatch/models.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'app/dispatch/models.py') 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) -- cgit v1.2.3