From 12701afd7481ae7bfed87b9972a79246475be12e Mon Sep 17 00:00:00 2001 From: Jeremy Stretch Date: Wed, 30 Jul 2025 13:44:25 -0400 Subject: [PATCH] Add html_tag property to ImageAttachment --- netbox/extras/models/models.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/netbox/extras/models/models.py b/netbox/extras/models/models.py index fc69e692c..d687aa821 100644 --- a/netbox/extras/models/models.py +++ b/netbox/extras/models/models.py @@ -9,6 +9,8 @@ from django.core.validators import ValidationError from django.db import models from django.urls import reverse from django.utils import timezone +from django.utils.html import escape +from django.utils.safestring import mark_safe from django.utils.translation import gettext_lazy as _ from rest_framework.utils.encoders import JSONEncoder @@ -728,6 +730,18 @@ class ImageAttachment(ChangeLoggedModel): def filename(self): return os.path.basename(self.image.name).split('_', 2)[2] + @property + def html_tag(self): + """ + Returns a complete tag suitable for embedding in an HTML document. + """ + return mark_safe('{alt_text}'.format( + url=self.image.url, + height=self.image_height, + width=self.image_width, + alt_text=escape(self.description or self.name), + )) + @property def size(self): """