Add tenant to floor plans with tenant filters

Floor plans get an optional tenant (inherited from location or site on
creation; existing plans are pre-filled by the migration). The list
view supports tenant and tenant group filtering and columns, and the
tenant is exposed in forms, CSV import, REST API and the detail page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
MrBlakeandClaude Opus 5.5 committed 2026-11-04 13:04:15 +01:00
1 parent 805aedba52
commit 04a6e16975
16 files changed
+87 -16

No files matched your search

+3 -1
View File
@@ -3,6 +3,7 @@ from dcim.choices import DeviceStatusChoices, RackStatusChoices
from dcim.models import Device, Rack
from django.utils.translation import gettext as _
from netbox.api.serializers import NetBoxModelSerializer
from tenancy.api.serializers import TenantSerializer
from rest_framework import serializers
from ..models import FloorPlan, FloorPlanItem
@@ -14,12 +15,13 @@ class FloorPlanSerializer(NetBoxModelSerializer):
url = serializers.HyperlinkedIdentityField(view_name='plugins-api:netbox_floorplanner-api:floorplan-detail')
site = SiteSerializer(nested=True)
location = LocationSerializer(nested=True, required=False, allow_null=True, default=None)
tenant = TenantSerializer(nested=True, required=False, allow_null=True, default=None)
item_count = serializers.IntegerField(read_only=True, required=False)
class Meta:
model = FloorPlan
fields = (
'id', 'url', 'display', 'name', 'site', 'location', 'width', 'depth', 'grid_size',
'id', 'url', 'display', 'name', 'site', 'location', 'tenant', 'width', 'depth', 'grid_size',
'background_image', 'background_opacity', 'description', 'comments', 'item_count',
'tags', 'custom_fields', 'created', 'last_updated',
)
+1 -1
View File
@@ -10,7 +10,7 @@ from .serializers import FloorPlanItemSerializer, FloorPlanSerializer, LayoutSer
class FloorPlanViewSet(NetBoxModelViewSet):
queryset = FloorPlan.objects.select_related('site', 'location').prefetch_related('tags').annotate(
queryset = FloorPlan.objects.select_related('site', 'location', 'tenant').prefetch_related('tags').annotate(
item_count=Count('items')
)
serializer_class = FloorPlanSerializer