mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 07:05:41 +00:00 
			
		
		
		
	adds a "link" field to the InvenTree attachment model
- Allows attachments to also serve as links to external files
This commit is contained in:
		@@ -21,7 +21,8 @@ from django.dispatch import receiver
 | 
			
		||||
from mptt.models import MPTTModel, TreeForeignKey
 | 
			
		||||
from mptt.exceptions import InvalidMove
 | 
			
		||||
 | 
			
		||||
from .validators import validate_tree_name
 | 
			
		||||
from InvenTree.fields import InvenTreeURLField
 | 
			
		||||
from InvenTree.validators import validate_tree_name
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
logger = logging.getLogger('inventree')
 | 
			
		||||
@@ -89,6 +90,8 @@ class ReferenceIndexingMixin(models.Model):
 | 
			
		||||
class InvenTreeAttachment(models.Model):
 | 
			
		||||
    """ Provides an abstracted class for managing file attachments.
 | 
			
		||||
 | 
			
		||||
    An attachment can be either an uploaded file, or an external URL
 | 
			
		||||
 | 
			
		||||
    Attributes:
 | 
			
		||||
        attachment: File
 | 
			
		||||
        comment: String descriptor for the attachment
 | 
			
		||||
@@ -107,7 +110,15 @@ class InvenTreeAttachment(models.Model):
 | 
			
		||||
        return os.path.basename(self.attachment.name)
 | 
			
		||||
 | 
			
		||||
    attachment = models.FileField(upload_to=rename_attachment, verbose_name=_('Attachment'),
 | 
			
		||||
                                  help_text=_('Select file to attach'))
 | 
			
		||||
                                  help_text=_('Select file to attach'),
 | 
			
		||||
                                  blank=True, null=True
 | 
			
		||||
                                  )
 | 
			
		||||
 | 
			
		||||
    link = InvenTreeURLField(
 | 
			
		||||
        blank=True, null=True,
 | 
			
		||||
        verbose_name=_('Link'),
 | 
			
		||||
        help_text=_('Link to external URL')
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    comment = models.CharField(blank=True, max_length=100, verbose_name=_('Comment'), help_text=_('File comment'))
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										25
									
								
								InvenTree/build/migrations/0033_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								InvenTree/build/migrations/0033_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# Generated by Django 3.2.5 on 2021-11-28 01:51
 | 
			
		||||
 | 
			
		||||
import InvenTree.fields
 | 
			
		||||
import InvenTree.models
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('build', '0032_auto_20211014_0632'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.AddField(
 | 
			
		||||
            model_name='buildorderattachment',
 | 
			
		||||
            name='link',
 | 
			
		||||
            field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL', null=True, verbose_name='Link'),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AlterField(
 | 
			
		||||
            model_name='buildorderattachment',
 | 
			
		||||
            name='attachment',
 | 
			
		||||
            field=models.FileField(blank=True, help_text='Select file to attach', null=True, upload_to=InvenTree.models.rename_attachment, verbose_name='Attachment'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										35
									
								
								InvenTree/order/migrations/0053_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								InvenTree/order/migrations/0053_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
# Generated by Django 3.2.5 on 2021-11-28 01:51
 | 
			
		||||
 | 
			
		||||
import InvenTree.fields
 | 
			
		||||
import InvenTree.models
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('order', '0052_auto_20211014_0631'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.AddField(
 | 
			
		||||
            model_name='purchaseorderattachment',
 | 
			
		||||
            name='link',
 | 
			
		||||
            field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL', null=True, verbose_name='Link'),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AddField(
 | 
			
		||||
            model_name='salesorderattachment',
 | 
			
		||||
            name='link',
 | 
			
		||||
            field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL', null=True, verbose_name='Link'),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AlterField(
 | 
			
		||||
            model_name='purchaseorderattachment',
 | 
			
		||||
            name='attachment',
 | 
			
		||||
            field=models.FileField(blank=True, help_text='Select file to attach', null=True, upload_to=InvenTree.models.rename_attachment, verbose_name='Attachment'),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AlterField(
 | 
			
		||||
            model_name='salesorderattachment',
 | 
			
		||||
            name='attachment',
 | 
			
		||||
            field=models.FileField(blank=True, help_text='Select file to attach', null=True, upload_to=InvenTree.models.rename_attachment, verbose_name='Attachment'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										25
									
								
								InvenTree/part/migrations/0075_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								InvenTree/part/migrations/0075_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# Generated by Django 3.2.5 on 2021-11-28 01:51
 | 
			
		||||
 | 
			
		||||
import InvenTree.fields
 | 
			
		||||
import InvenTree.models
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('part', '0074_partcategorystar'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.AddField(
 | 
			
		||||
            model_name='partattachment',
 | 
			
		||||
            name='link',
 | 
			
		||||
            field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL', null=True, verbose_name='Link'),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AlterField(
 | 
			
		||||
            model_name='partattachment',
 | 
			
		||||
            name='attachment',
 | 
			
		||||
            field=models.FileField(blank=True, help_text='Select file to attach', null=True, upload_to=InvenTree.models.rename_attachment, verbose_name='Attachment'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
							
								
								
									
										25
									
								
								InvenTree/stock/migrations/0070_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								InvenTree/stock/migrations/0070_auto_20211128_0151.py
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# Generated by Django 3.2.5 on 2021-11-28 01:51
 | 
			
		||||
 | 
			
		||||
import InvenTree.fields
 | 
			
		||||
import InvenTree.models
 | 
			
		||||
from django.db import migrations, models
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Migration(migrations.Migration):
 | 
			
		||||
 | 
			
		||||
    dependencies = [
 | 
			
		||||
        ('stock', '0069_auto_20211109_2347'),
 | 
			
		||||
    ]
 | 
			
		||||
 | 
			
		||||
    operations = [
 | 
			
		||||
        migrations.AddField(
 | 
			
		||||
            model_name='stockitemattachment',
 | 
			
		||||
            name='link',
 | 
			
		||||
            field=InvenTree.fields.InvenTreeURLField(blank=True, help_text='Link to external URL', null=True, verbose_name='Link'),
 | 
			
		||||
        ),
 | 
			
		||||
        migrations.AlterField(
 | 
			
		||||
            model_name='stockitemattachment',
 | 
			
		||||
            name='attachment',
 | 
			
		||||
            field=models.FileField(blank=True, help_text='Select file to attach', null=True, upload_to=InvenTree.models.rename_attachment, verbose_name='Attachment'),
 | 
			
		||||
        ),
 | 
			
		||||
    ]
 | 
			
		||||
		Reference in New Issue
	
	Block a user