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]>
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
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),
|
|
]
|