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:
1 parent
04a6e16975
commit
25e944ada7
6 files changed
+39
-7
No files matched your search
@@ -1,7 +1,7 @@
|
|||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from netbox.plugins import PluginConfig
|
from netbox.plugins import PluginConfig
|
||||||
|
|
||||||
__version__ = '0.1.3'
|
__version__ = '0.1.4'
|
||||||
|
|
||||||
|
|
||||||
class FloorPlannerConfig(PluginConfig):
|
class FloorPlannerConfig(PluginConfig):
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('dcim', '__first__'),
|
||||||
|
('netbox_floorplanner', '0002_floorplan_tenant'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='floorplanitem',
|
||||||
|
name='rack',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='dcim.rack',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='floorplanitem',
|
||||||
|
name='device',
|
||||||
|
field=models.ForeignKey(
|
||||||
|
blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='+', to='dcim.device',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
]
|
||||||
@@ -4,6 +4,7 @@ from django.db import models
|
|||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
from netbox.models import NetBoxModel
|
from netbox.models import NetBoxModel
|
||||||
|
from utilities.querysets import RestrictedQuerySet
|
||||||
|
|
||||||
from .choices import ItemTypeChoices
|
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
|
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.
|
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(
|
floorplan = models.ForeignKey(
|
||||||
to=FloorPlan,
|
to=FloorPlan,
|
||||||
@@ -117,7 +120,7 @@ class FloorPlanItem(models.Model):
|
|||||||
rack = models.ForeignKey(
|
rack = models.ForeignKey(
|
||||||
to='dcim.Rack',
|
to='dcim.Rack',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='floorplan_items',
|
related_name='+',
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
verbose_name=_('rack'),
|
verbose_name=_('rack'),
|
||||||
@@ -125,13 +128,15 @@ class FloorPlanItem(models.Model):
|
|||||||
device = models.ForeignKey(
|
device = models.ForeignKey(
|
||||||
to='dcim.Device',
|
to='dcim.Device',
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
related_name='floorplan_items',
|
related_name='+',
|
||||||
blank=True,
|
blank=True,
|
||||||
null=True,
|
null=True,
|
||||||
verbose_name=_('device'),
|
verbose_name=_('device'),
|
||||||
)
|
)
|
||||||
properties = models.JSONField(verbose_name=_('properties'), default=dict, blank=True)
|
properties = models.JSONField(verbose_name=_('properties'), default=dict, blank=True)
|
||||||
|
|
||||||
|
objects = RestrictedQuerySet.as_manager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ('floorplan', 'z_index', 'pk')
|
ordering = ('floorplan', 'z_index', 'pk')
|
||||||
verbose_name = _('floor plan item')
|
verbose_name = _('floor plan item')
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.3">
|
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.4">
|
||||||
<div class="fp-root" data-fp-config="fp-config">{% csrf_token %}</div>
|
<div class="fp-root" data-fp-config="fp-config">{% csrf_token %}</div>
|
||||||
{{ designer_config|json_script:"fp-config" }}
|
{{ designer_config|json_script:"fp-config" }}
|
||||||
<script src="{% static 'netbox_floorplanner/floorplanner.js' %}?v=0.1.3"></script>
|
<script src="{% static 'netbox_floorplanner/floorplanner.js' %}?v=0.1.4"></script>
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{% load static %}
|
{% load static %}
|
||||||
{% load i18n %}
|
{% load i18n %}
|
||||||
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.3">
|
<link rel="stylesheet" href="{% static 'netbox_floorplanner/floorplanner.css' %}?v=0.1.4">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<h2 class="card-header">{% trans "Floor Plans" %}</h2>
|
<h2 class="card-header">{% trans "Floor Plans" %}</h2>
|
||||||
<div class="card-body fp-preview-list">
|
<div class="card-body fp-preview-list">
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|||||||
|
|
||||||
[project]
|
[project]
|
||||||
name = "netbox-floorplanner"
|
name = "netbox-floorplanner"
|
||||||
version = "0.1.3"
|
version = "0.1.4"
|
||||||
description = "Modern drag & drop floor plan designer for NetBox 4.7+"
|
description = "Modern drag & drop floor plan designer for NetBox 4.7+"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
|
|||||||
Reference in new issue
Block a user