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

@@ -0,0 +1,32 @@
import django.db.models.deletion
from django.db import migrations, models
def inherit_tenant(apps, schema_editor):
"""Pre-fill the tenant of existing floor plans from their location or site."""
FloorPlan = apps.get_model('netbox_floorplanner', 'FloorPlan')
for plan in FloorPlan.objects.select_related('site', 'location').filter(tenant__isnull=True):
tenant_id = (plan.location.tenant_id if plan.location_id else None) or plan.site.tenant_id
if tenant_id:
plan.tenant_id = tenant_id
plan.save(update_fields=['tenant'])
class Migration(migrations.Migration):
dependencies = [
('tenancy', '__first__'),
('netbox_floorplanner', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='floorplan',
name='tenant',
field=models.ForeignKey(
blank=True, null=True, on_delete=django.db.models.deletion.PROTECT,
related_name='floorplans', to='tenancy.tenant',
),
),
migrations.RunPython(inherit_tenant, migrations.RunPython.noop),
]