fix: stack members show the whole switch stack in the port panel and PDF

The current device is marked in the panel.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-04 09:17:34 +01:00
1 parent ce174c6541
commit 356034fe98
6 files changed
+27 -12

No files matched your search

+13
View File
@@ -19,6 +19,19 @@ def stack_members(device):
return sorted(members, key=lambda member: natural_key(member.name or str(member)))
def stack_units(device):
"""[stack switch, *members] for a stack switch or one of its members; [device] outside a stack."""
if device is None or not device.pk:
return [device]
stack = (
SwitchStack.objects.filter(device=device).select_related("device").first()
or SwitchStack.objects.filter(members=device).select_related("device").first()
)
if stack is None:
return [device]
return [stack.device, *stack_members(stack.device)]
def build_stack_form_mixin():
from dcim.models import Device
from utilities.forms.fields import DynamicModelMultipleChoiceField