Bug fixes

- Part creation form was setting a field as HiddenInput() rather than its widget
- Added 'comment' file to FileAttachment model
This commit is contained in:
Oliver Walters 2019-05-01 09:40:49 +10:00
parent 7dd960a299
commit 7c11d917de
4 changed files with 26 additions and 3 deletions

View File

@ -19,7 +19,7 @@ class PartCategoryAdmin(ImportExportModelAdmin):
class PartAttachmentAdmin(admin.ModelAdmin):
list_display = ('part', 'attachment')
list_display = ('part', 'attachment', 'comment')
class BomItemAdmin(ImportExportModelAdmin):

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2 on 2019-04-30 23:34
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('part', '0013_auto_20190429_2229'),
]
operations = [
migrations.AddField(
model_name='partattachment',
name='comment',
field=models.CharField(blank=True, help_text='Attachment description', max_length=100),
),
]

View File

@ -366,6 +366,8 @@ class PartAttachment(models.Model):
attachment = models.FileField(upload_to=attach_file, null=True, blank=True)
comment = models.CharField(max_length=100, blank=True, help_text="Attachment description")
@property
def basename(self):
return os.path.basename(self.attachment.name)
@ -405,8 +407,11 @@ class BomItem(models.Model):
- A part cannot refer to a part which refers to it
"""
if self.part is None or self.sub_part is None:
# Field validation will catch these None values
pass
# A part cannot refer to itself in its BOM
if self.part == self.sub_part:
elif self.part == self.sub_part:
raise ValidationError({'sub_part': _('Part cannot be added to its own Bill of Materials')})
# Test for simple recursion

View File

@ -98,7 +98,7 @@ class PartCreate(AjaxCreateView):
form = super(AjaxCreateView, self).get_form()
# Hide the default_supplier field (there are no matching supplier parts yet!)
form.fields['default_supplier'] = HiddenInput()
form.fields['default_supplier'].widget = HiddenInput()
return form