diff --git a/netbox_topology_views/tables.py b/netbox_topology_views/tables.py index 53d4f0e..da09ea2 100644 --- a/netbox_topology_views/tables.py +++ b/netbox_topology_views/tables.py @@ -7,11 +7,12 @@ class CoordinateGroupListTable(NetBoxTable): name = tables.Column( linkify=True ) + devices = tables.Column() class Meta(NetBoxTable.Meta): model = CoordinateGroup - fields = ('pk', 'name', 'description') - default_columns = ('name', 'description') + fields = ('pk', 'id', 'name', 'description', 'devices') + default_columns = ('name', 'description', 'devices') class CoordinateListTable(NetBoxTable): group = tables.Column( @@ -24,6 +25,6 @@ class CoordinateListTable(NetBoxTable): class Meta(NetBoxTable.Meta): model = Coordinate - fields = ('pk', 'group', 'device', 'x', 'y') + fields = ('pk', 'id', 'group', 'device', 'x', 'y') default_columns = ('id', 'group', 'device', 'x', 'y') diff --git a/netbox_topology_views/templates/netbox_topology_views/coordinate.html b/netbox_topology_views/templates/netbox_topology_views/coordinate.html index 1ffc230..ab03343 100644 --- a/netbox_topology_views/templates/netbox_topology_views/coordinate.html +++ b/netbox_topology_views/templates/netbox_topology_views/coordinate.html @@ -1,7 +1,6 @@ {% extends 'generic/object.html' %} {% load helpers %} {% load plugins %} -{% load render_table from django_tables2 %} {% block title %}Topology Views Coordinates{% endblock title %} @@ -16,11 +15,11 @@ - + - + diff --git a/netbox_topology_views/templates/netbox_topology_views/coordinategroup.html b/netbox_topology_views/templates/netbox_topology_views/coordinategroup.html index a8e0db1..5b79814 100644 --- a/netbox_topology_views/templates/netbox_topology_views/coordinategroup.html +++ b/netbox_topology_views/templates/netbox_topology_views/coordinategroup.html @@ -32,4 +32,14 @@ {% plugin_right_page object %} +
+
+
+
Coordinates
+
+ {% render_table coordinates_table %} +
+
+
+
{% endblock content %} \ No newline at end of file diff --git a/netbox_topology_views/urls.py b/netbox_topology_views/urls.py index 1b96f58..2da3a95 100644 --- a/netbox_topology_views/urls.py +++ b/netbox_topology_views/urls.py @@ -1,6 +1,6 @@ from django.urls import path from django.views.generic.base import RedirectView - +from netbox.views.generic import ObjectChangeLogView from . import models, views # Define a list of URL patterns to be imported by NetBox. Each pattern maps a URL to @@ -17,7 +17,7 @@ urlpatterns = ( path("coordinate-groups//", views.CoordinateGroupView.as_view(), name="coordinategroup"), path("coordinate-groups//edit/", views.CoordinateGroupEditView.as_view(), name="coordinategroup_edit"), path("coordinate-groups//delete/", views.CoordinateGroupDeleteView.as_view(), name="coordinategroup_delete"), - path("coordinate-groups//changelog/", views.CoordinateGroupChangeLogView.as_view(), name="coordinategroup_changelog", kwargs={'model': models.CoordinateGroup}), + path("coordinate-groups//changelog/", ObjectChangeLogView.as_view(), name="coordinategroup_changelog", kwargs={'model': models.CoordinateGroup}), # Coordinate path("coordinate/", views.CoordinateListView.as_view(), name="coordinate_list"), @@ -25,5 +25,5 @@ urlpatterns = ( path("coordinate//", views.CoordinateView.as_view(), name="coordinate"), path("coordinate//edit/", views.CoordinateEditView.as_view(), name="coordinate_edit"), path("coordinate//delete/", views.CoordinateDeleteView.as_view(), name="coordinate_delete"), - path("coordinate//changelog/", views.CoordinateChangeLogView.as_view(), name="coordinate_changelog", kwargs={'model': models.Coordinate}), + path("coordinate//changelog/", ObjectChangeLogView.as_view(), name="coordinate_changelog", kwargs={'model': models.Coordinate}), ) diff --git a/netbox_topology_views/views.py b/netbox_topology_views/views.py index 7ef10b0..69f1563 100644 --- a/netbox_topology_views/views.py +++ b/netbox_topology_views/views.py @@ -22,7 +22,7 @@ from django.conf import settings from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.contenttypes.models import ContentType -from django.db.models import Q, QuerySet +from django.db.models import Q, QuerySet, Count from django.db.models.functions import Lower from django.http import HttpRequest, HttpResponseRedirect, QueryDict from django.shortcuts import render, get_object_or_404 @@ -825,6 +825,14 @@ class CoordinateGroupView(PermissionRequiredMixin, ObjectView): queryset = CoordinateGroup.objects.all() + def get_extra_context(self, request, instance): + table = CoordinateListTable(instance.coordinate_set.all()) + table.configure(request) + + return { + 'coordinates_table': table, + } + class CoordinateGroupAddView(PermissionRequiredMixin, ObjectEditView): permission_required = 'netbox_topology_views.add_coordinategroup' @@ -835,7 +843,9 @@ class CoordinateGroupAddView(PermissionRequiredMixin, ObjectEditView): class CoordinateGroupListView(PermissionRequiredMixin, ObjectListView): permission_required = 'netbox_topology_views.view_coordinategroup' - queryset = CoordinateGroup.objects.all() + queryset = CoordinateGroup.objects.annotate( + devices = Count('coordinate') + ) table = CoordinateGroupListTable template_name = 'netbox_topology_views/coordinategroup_list.html'
Group{{ object.group }}{{ object.group|linkify }}
Device{{ object.device }}{{ object.device|linkify }}
X-Coordinate