Skip to content

Conversation

@hagbarddenstore
Copy link
Contributor

Fixes: #9686

Add a column to display Tenant Group on tables which already displays the Tenant.

Works the same as the existing TenantColumn, but displats the Tenant Group of
the Tenant.

Views should prefetch the Tenants Group for this to be efficient in large
tables.
A mixin to add the Tenant and Tenant Group columns to a table.
Replaces all usages of the TenantColumn with the new TenancyColumnsMixin.

This enables the user to add a column for Tenant Group on all tables which
also has a column for Tenant.
Configure the prefetch to also include the Tenant Group, avoids additional
database queries when the Tenant Group column is to be rendered.

NOTE: If no personalisation of the global search tables should be done,
this commit can be reverted.
Removes the Tenant Group column from tables which aren't configurable
by the user.
Prefetch the Tenant Group in views which allows its table to be configured
by the user. This decreases the amount of database queries that are required
to fetch the data.
Include the tenant group description.
"""
template_code = """
{% if record.tenant and record.tenant.group %}
Copy link
Member

Choose a reason for hiding this comment

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

This is where we need to be careful with regard to prefetching. Because the column itself doesn't define an accessor, the tenant group doesn't get prefetched in the queryset. Instead, a separate query is made for tenant.group as needed for each unique tenant. I think we can resolve this by specifying tenant__group as the accessor for the column and tweaking the template code, but I'll merge this as-is and try a few things.

@jeremystretch
Copy link
Member

Thanks for taking this!

@jeremystretch jeremystretch merged commit a49d3d2 into netbox-community:develop Jul 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Tenant Group column to tables

2 participants