Skip to content

Closes #18204: Miscellaneous improvements to the display of image attachments #19914

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions netbox/extras/filtersets.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ def search(self, queryset, name, value):
return queryset
return queryset.filter(
Q(name__icontains=value) |
Q(image__icontains=value) |
Q(description__icontains=value)
)

Expand Down
1 change: 1 addition & 0 deletions netbox/extras/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class ImageAttachmentIndex(SearchIndex):
model = models.ImageAttachment
fields = (
('name', 100),
('filename', 110),
('description', 500),
)
display_attrs = ('description',)
Expand Down
47 changes: 35 additions & 12 deletions netbox/extras/tables/tables.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json

import django_tables2 as tables
from django.template.defaultfilters import filesizeformat
from django.utils.html import format_html
from django.utils.translation import gettext_lazy as _

Expand Down Expand Up @@ -38,10 +39,11 @@

IMAGEATTACHMENT_IMAGE = """
{% if record.image %}
<a class="image-preview" href="{{ record.image.url }}" target="_blank">{{ record }}</a>
{% else %}
&mdash;
<a class="image-preview" href="{{ record.image.url }}" target="_blank">
<i class="mdi mdi-image"></i>
</a>
{% endif %}
<a href="{{ record.get_absolute_url }}">{{ record }}</a>
"""

NOTIFICATION_ICON = """
Expand Down Expand Up @@ -230,29 +232,50 @@ class ImageAttachmentTable(NetBoxTable):
verbose_name=_('ID'),
linkify=False
)
image = columns.TemplateColumn(
verbose_name=_('Image'),
template_code=IMAGEATTACHMENT_IMAGE,
)
name = tables.Column(
verbose_name=_('Name'),
linkify=True,
)
filename = tables.Column(
verbose_name=_('Filename'),
linkify=lambda record: record.image.url,
orderable=False,
)
dimensions = columns.TemplateColumn(
verbose_name=_('Dimensions'),
orderable=False,
template_code="{{ record.image_width }}×{{ record.image_height }}",
)
object_type = columns.ContentTypeColumn(
verbose_name=_('Object Type'),
)
parent = tables.Column(
verbose_name=_('Parent'),
linkify=True
)
image = tables.TemplateColumn(
verbose_name=_('Image'),
template_code=IMAGEATTACHMENT_IMAGE,
linkify=True,
orderable=False,
)
size = tables.Column(
orderable=False,
verbose_name=_('Size (Bytes)')
verbose_name=_('Size')
)

class Meta(NetBoxTable.Meta):
model = ImageAttachment
fields = (
'pk', 'object_type', 'parent', 'image', 'name', 'description', 'image_height', 'image_width', 'size',
'created', 'last_updated',
'pk', 'object_type', 'parent', 'image', 'name', 'filename', 'description', 'image_height', 'image_width',
'size', 'created', 'last_updated',
)
default_columns = ('object_type', 'parent', 'image', 'name', 'description', 'size', 'created')
default_columns = ('image', 'parent', 'description', 'dimensions', 'size')

def render_size(self, value):
return filesizeformat(value)

def value_size(self, value):
return value


class SavedFilterTable(NetBoxTable):
Expand Down