diff --git a/InvenTree/InvenTree/models.py b/InvenTree/InvenTree/models.py index 2c1422da56..85a595a9ce 100644 --- a/InvenTree/InvenTree/models.py +++ b/InvenTree/InvenTree/models.py @@ -440,7 +440,8 @@ class InvenTreeAttachment(models.Model): An attachment can be either an uploaded file, or an external URL Attributes: - attachment: File + attachment: Upload file + link: External URL comment: String descriptor for the attachment user: User associated with file upload upload_date: Date the file was uploaded @@ -564,6 +565,22 @@ class InvenTreeAttachment(models.Model): except Exception: raise ValidationError(_("Error renaming file")) + def fully_qualified_url(self): + """Return a 'fully qualified' URL for this attachment. + + - If the attachment is a link to an external resource, return the link + - If the attachment is an uploaded file, return the fully qualified media URL + """ + + if self.link: + return self.link + + if self.attachment: + media_url = InvenTree.helpers.getMediaUrl(self.attachment.url) + return InvenTree.helpers_model.construct_absolute_url(media_url) + + return '' + class InvenTreeTree(MPTTModel): """Provides an abstracted self-referencing tree model for data categories.