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

+6 -1
View File
@@ -15,7 +15,7 @@ from .utils import format_meters, format_room_size
def floorplans_queryset():
return FloorPlan.objects.select_related('site', 'location').annotate(
return FloorPlan.objects.select_related('site', 'location', 'tenant').annotate(
item_count=Count('items', distinct=True),
rack_count=Count('items', filter=Q(items__rack__isnull=False), distinct=True),
)
@@ -104,6 +104,11 @@ class FloorPlanEditView(generic.ObjectEditView):
obj.site_id = site_id
if location_id := request.GET.get('location'):
obj.location_id = location_id
# Inherit the tenant from the location or site
if obj.location_id and (location := Location.objects.filter(pk=obj.location_id).first()):
obj.tenant_id = location.tenant_id
if not obj.tenant_id and obj.site_id and (site := Site.objects.filter(pk=obj.site_id).first()):
obj.tenant_id = site.tenant_id
return obj