From 6f465f28cd681c3fd9418f9edd7e91ec238ffbb2 Mon Sep 17 00:00:00 2001 From: Mitch Riedstra Date: Fri, 13 Oct 2017 13:29:52 -0400 Subject: Updated migrations, removed comments, and changed the model from one to one to foreign key to allow for multiple documents per load --- app/dispatch/forms.py | 29 ++++--------------- app/dispatch/migrations/0001_initial.py | 13 +++++++-- app/dispatch/migrations/0002_auto_20171010_0140.py | 20 ------------- app/dispatch/migrations/0003_paperwork.py | 25 ---------------- app/dispatch/models.py | 5 ++-- app/dispatch/views.py | 33 ---------------------- 6 files changed, 20 insertions(+), 105 deletions(-) delete mode 100644 app/dispatch/migrations/0002_auto_20171010_0140.py delete mode 100644 app/dispatch/migrations/0003_paperwork.py diff --git a/app/dispatch/forms.py b/app/dispatch/forms.py index 25ebcd7..f3059ee 100644 --- a/app/dispatch/forms.py +++ b/app/dispatch/forms.py @@ -1,30 +1,8 @@ from django import forms -from dispatch.models import Paperwork +from dispatch.models import Paperwork, Load from django.conf import settings -# class PaperworkForm(forms.ModelForm): -# class Meta: -# model = Paperwork -# fields = ('load', 'description', 'document') - -# class AddPaperworkForm(forms.Form): -# # load_number = forms.CharField(max_length=64,default="") -# date = forms.DateField() -# user = forms.ForeignKey(settings.AUTH_USER_MODEL) -# company = forms.ForeignKey(Company) -# description = forms.CharField(max_length=256) -# amount = forms.DecimalField(max_digits=10,decimal_places=2, default="0") -# -# document_description = forms.CharField(max_length=256) -# document = forms.FileField(upload_to='paperwork/') -# -# class Meta: -# model = Paperwork -# fields = ('load', 'description', 'document') - - - class AddPaperworkForm(forms.ModelForm): class Meta: model = Paperwork @@ -32,3 +10,8 @@ class AddPaperworkForm(forms.ModelForm): # fields = ('load', 'description', 'document') fields = ('description', 'document') # exclude = ('load',) + +class EditLoadForm(forms.ModelForm): + class Meta: + model = Load + fields = ('date', 'user', 'company', 'load_number', 'description', 'amount') diff --git a/app/dispatch/migrations/0001_initial.py b/app/dispatch/migrations/0001_initial.py index 581c3d5..b93c66b 100644 --- a/app/dispatch/migrations/0001_initial.py +++ b/app/dispatch/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.5 on 2017-10-09 18:26 +# Generated by Django 1.11.5 on 2017-10-13 14:52 from __future__ import unicode_literals from django.conf import settings @@ -34,9 +34,18 @@ class Migration(migrations.Migration): ('load_number', models.CharField(default='', max_length=64)), ('date', models.DateField()), ('description', models.CharField(max_length=256)), - ('amount', models.DecimalField(decimal_places=2, max_digits=10)), + ('amount', models.DecimalField(decimal_places=2, default='0', max_digits=10)), ('company', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dispatch.Company')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), ], ), + migrations.CreateModel( + name='Paperwork', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('description', models.CharField(max_length=256)), + ('document', models.FileField(upload_to='paperwork/')), + ('load', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dispatch.Load')), + ], + ), ] diff --git a/app/dispatch/migrations/0002_auto_20171010_0140.py b/app/dispatch/migrations/0002_auto_20171010_0140.py deleted file mode 100644 index 499153b..0000000 --- a/app/dispatch/migrations/0002_auto_20171010_0140.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.5 on 2017-10-10 01:40 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('dispatch', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='load', - name='amount', - field=models.DecimalField(decimal_places=2, default='0', max_digits=10), - ), - ] diff --git a/app/dispatch/migrations/0003_paperwork.py b/app/dispatch/migrations/0003_paperwork.py deleted file mode 100644 index 72c27d3..0000000 --- a/app/dispatch/migrations/0003_paperwork.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11.5 on 2017-10-11 16:15 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('dispatch', '0002_auto_20171010_0140'), - ] - - operations = [ - migrations.CreateModel( - name='Paperwork', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('description', models.CharField(max_length=256)), - ('document', models.FileField(upload_to='paperwork/')), - ('load', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to='dispatch.Load')), - ], - ), - ] diff --git a/app/dispatch/models.py b/app/dispatch/models.py index acb13cd..13b4e8b 100644 --- a/app/dispatch/models.py +++ b/app/dispatch/models.py @@ -26,12 +26,13 @@ class Load(models.Model): return "{c}, {d} ( {a} )".format(c=self.company, d=self.description, a=self.amount) class Paperwork(models.Model): - load = models.OneToOneField(Load) + 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/') def __str__(self): - return "%s" % Load + return "%s" % self.load diff --git a/app/dispatch/views.py b/app/dispatch/views.py index 6e28cbc..c436b7d 100644 --- a/app/dispatch/views.py +++ b/app/dispatch/views.py @@ -238,47 +238,14 @@ def PaperworkUpload(request, load_id): l = Load.objects.get(pk=load_id) if request.method == 'POST': form = AddPaperworkForm(request.POST, request.FILES) - print(request.POST) - print(request.FILES) - print("Form is: {}".format(form.is_valid())); if form.is_valid(): pw = form.save(commit=False) - print("------\nPW OBJECT:\n{}\n-----".format(pw)) pw.load = l pw.save() return redirect(reverse('load_edit', kwargs={'pk': load_id})) - # elif not form.is_valid(): - # print(form.errors()) else: form = AddPaperworkForm() ctx = { 'form': form, 'load': l } return render(request, 'dispatch/paperwork/add.html', ctx) - -# def PaperworkUpload(request, load_id): -# print(request, load_id) -# -# ctx = {} -# -# l = Load.objects.get(pk=load_id) -# -# ctx['load'] = l -# -# print(l) -# -# if request.method == 'POST': -# form = Paperwork(request.POST, request.FILES) -# if form.is_valid(): -# # file is saved -# form.save() -# return HttpResponseRedirect('/success/url/') -# else: -# form = Paperwork() -# -# -# ctx['form'] = form -# -# # return redirect(reverse('load_edit', kwargs={'pk': load_id})) -# # return render(request, 'dispatch/paperwork/add.html', {'form': form}) -# return render(request, 'dispatch/paperwork/add.html', ctx) -- cgit v1.2.3