Skip to content

Add optional Front Image, Rear Image, and Image Count columns to Device Type and Module Type tables#22706

Open
TallesH13 wants to merge 2 commits into
netbox-community:mainfrom
cgiestas:feat/img-counters
Open

Add optional Front Image, Rear Image, and Image Count columns to Device Type and Module Type tables#22706
TallesH13 wants to merge 2 commits into
netbox-community:mainfrom
cgiestas:feat/img-counters

Conversation

@TallesH13

Copy link
Copy Markdown

Closes: #22030

What this PR does

Adds three optional columns to the Device Type list view (Front Image, Rear Image and Images as the attached images counter) and one optional column to the Module Type list view (Images column, as the attached images counter)

Changes

  • Added front_image, rear_image and image_count columns to the Device Type table and image_count for Module Type table
  • Updated the corresponding filterset and view logic to support these columns
  • Columns are opt-in via the existing "Configure table" UI, consistent with other optional columns in Netbox

Testing

Verified manually and via local Cypress tests that:

  • The three columns appear as available options in "Configure Table"
  • Selecting and applying them renders the correct data in the table
  • Existing table behavior is unaffected

Screenshots

  • Device Type with changes
WhatsApp Image 2026-07-17 at 11 46 44 WhatsApp Image 2026-07-17 at 11 45 59
  • Module Type with changes
WhatsApp Image 2026-07-17 at 11 47 08 WhatsApp Image 2026-07-17 at 11 43 48

Co-authored by: Christiane Giestas christianegiestas@gmail.com

cgiestas added 2 commits July 16, 2026 16:26
…de indentação de comentários

Co-authored-by: Christiane Giestas <christianegiestas@gmail.com>
@jeremystretch

Copy link
Copy Markdown
Member

@claude /review Only report on issues of potential concern; we don't need commentary on anything that doesn't require further consideration.

@jeremystretch
jeremystretch requested review from a team and arthanson and removed request for a team July 17, 2026 17:16
@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Claude finished @jeremystretch's task in 4m 12s —— View job


Review

  • Read changed files and analyze code
  • Identify issues of potential concern
  • Post review findings

Three issues worth addressing:

1. Missing translation wrapper in DeviceTypeFilterSet

netbox/dcim/filtersets.py:727 — the has_images label is missing _():

# Current (not translated)
label=('Has images'),

# Should match the ModuleTypeFilterSet version and all neighbors
label=_('Has images'),

The parentheses without a comma are just grouping, not a tuple — this is a plain string literal that won't be passed through gettext. Every other label in the same class uses _().

Fix this →


2. Count('images') should use distinct=True

netbox/dcim/views.py:1424 and 1790:

data = data.annotate(image_count=Count('images'))

When the has_images filter is active it adds a JOIN on extras_imageattachment. Without distinct=True, the Count will operate over the joined rows and return inflated values for any device/module type that has more than one image. This is the classic Django aggregation-with-JOIN problem on multi-valued relations:

data = data.annotate(image_count=Count('images', distinct=True))

Fix this →


3. No tests

The PR adds a new filterset field (has_images), new table columns, and a non-trivial get_table override — but no tests are included. Per the contributing guidelines, PRs must include tests for new functionality. At minimum:

  • test_filtersets.py — verify has_images=True/False returns the expected querysets
  • test_tables.py (or test_views.py) — verify image_count annotation is correct and front_image/rear_image columns render as expected

@arthanson arthanson left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @TallesH13 a couple issues to clean up.

Please add some tests: The PR adds a filter, filter form fields, and table columns with zero test coverage:

  • has_images filter tests for both models, mirroring test_has_front_image / test_has_rear_image at netbox/dcim/tests/test_filtersets.py:1520-1529.
  • A table-render test exercising image_count when the column is selected (this is the path with the most logic).

Column-visibility detection in get_table() is incomplete? To replicate:

  1. Add a front and rear image and image attachment to a device type.
  2. Go to configure table and add these columns. (note the display the checkmarks and count)
  3. In the configure table dropdown, save this configuration.
  4. Go to configure table and remove these fields.
  5. I the Configure table dropdown load your saved configuration.
  6. Note the columns show but they appear with a dash (no checkmark or count)

Table.configure() resolves visible columns from more sources (netbox/netbox/tables/tables.py:189-200 and mixins.py:54):

  • settings.DEFAULT_USER_PREFERENCES
  • ?include_columns=image_count (query param)
  • ?tableconfig_id=.

In all three paths the image_count column is displayed but the queryset isn't annotated.

Comment thread netbox/dcim/filtersets.py
)
has_images = django_filters.BooleanFilter(
method='_has_images',
label=('Has images'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need _( internationalization here

Comment thread netbox/dcim/views.py
filterset_form = forms.DeviceTypeFilterForm
table = tables.DeviceTypeTable

def get_table(self, data, request, bulk_actions=True):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated below, can we extract this out into a common place, maybe an ImageCountAnnotationMixin to keep it DRY

Comment thread .gitignore
*.egg-info/

# Ruff's locally generated cache
.ruff_cache No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is out of scope for the PR, can we remove this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add optional Image Indicators/Counters to Device Type and Module Type Tables

4 participants