Fix AttributeError on rack and device pages

NetBox 4.7 lists related objects via Model.objects.restrict(), which the
plain FloorPlanItem manager lacked. Drop the reverse accessors from rack
and device (related_name='+') and use a RestrictedQuerySet manager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-04 13:23:02 +01:00
1 parent 04a6e16975
commit 25e944ada7
6 files changed
+39 -7

No files matched your search

+7 -2
View File
@@ -4,6 +4,7 @@ from django.db import models
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from netbox.models import NetBoxModel
from utilities.querysets import RestrictedQuerySet
from .choices import ItemTypeChoices
@@ -94,6 +95,8 @@ class FloorPlanItem(models.Model):
"""
A single shape on a floor plan. Items are always written as a whole layout
through the layout API endpoint; changes are change-logged on the parent plan.
The rack/device relations have no reverse accessor, so NetBox does not list
items as "related objects" on rack and device pages.
"""
floorplan = models.ForeignKey(
to=FloorPlan,
@@ -117,7 +120,7 @@ class FloorPlanItem(models.Model):
rack = models.ForeignKey(
to='dcim.Rack',
on_delete=models.CASCADE,
related_name='floorplan_items',
related_name='+',
blank=True,
null=True,
verbose_name=_('rack'),
@@ -125,13 +128,15 @@ class FloorPlanItem(models.Model):
device = models.ForeignKey(
to='dcim.Device',
on_delete=models.CASCADE,
related_name='floorplan_items',
related_name='+',
blank=True,
null=True,
verbose_name=_('device'),
)
properties = models.JSONField(verbose_name=_('properties'), default=dict, blank=True)
objects = RestrictedQuerySet.as_manager()
class Meta:
ordering = ('floorplan', 'z_index', 'pk')
verbose_name = _('floor plan item')