From 9614963f167717271e34513144e4f93c556141c7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Wed, 17 Nov 2021 08:58:32 +1100 Subject: [PATCH] Put function into migration file --- InvenTree/part/migrations/0001_initial.py | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/InvenTree/part/migrations/0001_initial.py b/InvenTree/part/migrations/0001_initial.py index e5183e2b5c..066d1afa4b 100644 --- a/InvenTree/part/migrations/0001_initial.py +++ b/InvenTree/part/migrations/0001_initial.py @@ -1,13 +1,29 @@ # Generated by Django 2.2 on 2019-05-20 12:04 -import InvenTree.validators -from django.conf import settings -import django.core.validators +import os + from django.db import migrations, models import django.db.models.deletion +from django.conf import settings +import django.core.validators + +import InvenTree.validators import part.models +def attach_file(instance, filename): + """ + Generate a filename for the uploaded attachment. + + 2021-11-17 - This was moved here from part.models.py, + as the function itself is no longer used, + but is still required for migration + """ + + # Construct a path to store a file attachment + return os.path.join('part_files', str(instance.part.id), filename) + + class Migration(migrations.Migration): initial = True @@ -61,7 +77,7 @@ class Migration(migrations.Migration): name='PartAttachment', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('attachment', models.FileField(help_text='Select file to attach', upload_to=part.models.attach_file)), + ('attachment', models.FileField(help_text='Select file to attach', upload_to=attach_file)), ('comment', models.CharField(help_text='File comment', max_length=100)), ], ),