mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Initial work on #91: Support for subdevices
This commit is contained in:
@ -2,9 +2,9 @@ from django.contrib import admin
|
||||
from django.db.models import Count
|
||||
|
||||
from .models import (
|
||||
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType,
|
||||
Interface, InterfaceTemplate, Manufacturer, Module, Platform, PowerOutlet, PowerOutletTemplate, PowerPort,
|
||||
PowerPortTemplate, Rack, RackGroup, Site,
|
||||
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceBay,
|
||||
DeviceBayTemplate, DeviceRole, DeviceType, Interface, InterfaceTemplate, Manufacturer, Module, Platform,
|
||||
PowerOutlet, PowerOutletTemplate, PowerPort, PowerPortTemplate, Rack, RackGroup, Site,
|
||||
)
|
||||
|
||||
|
||||
@ -61,6 +61,10 @@ class InterfaceTemplateAdmin(admin.TabularInline):
|
||||
model = InterfaceTemplate
|
||||
|
||||
|
||||
class DeviceBayTemplateAdmin(admin.TabularInline):
|
||||
model = DeviceBayTemplate
|
||||
|
||||
|
||||
@admin.register(DeviceType)
|
||||
class DeviceTypeAdmin(admin.ModelAdmin):
|
||||
prepopulated_fields = {
|
||||
@ -72,9 +76,10 @@ class DeviceTypeAdmin(admin.ModelAdmin):
|
||||
PowerPortTemplateAdmin,
|
||||
PowerOutletTemplateAdmin,
|
||||
InterfaceTemplateAdmin,
|
||||
DeviceBayTemplateAdmin,
|
||||
]
|
||||
list_display = ['model', 'manufacturer', 'slug', 'u_height', 'console_ports', 'console_server_ports', 'power_ports',
|
||||
'power_outlets', 'interfaces']
|
||||
'power_outlets', 'interfaces', 'device_bays']
|
||||
list_filter = ['manufacturer']
|
||||
|
||||
def get_queryset(self, request):
|
||||
@ -84,6 +89,7 @@ class DeviceTypeAdmin(admin.ModelAdmin):
|
||||
power_port_count=Count('power_port_templates', distinct=True),
|
||||
power_outlet_count=Count('power_outlet_templates', distinct=True),
|
||||
interface_count=Count('interface_templates', distinct=True),
|
||||
devicebay_count=Count('devicebay_templates', distinct=True),
|
||||
)
|
||||
|
||||
def console_ports(self, instance):
|
||||
@ -101,6 +107,9 @@ class DeviceTypeAdmin(admin.ModelAdmin):
|
||||
def interfaces(self, instance):
|
||||
return instance.interface_count
|
||||
|
||||
def device_bays(self, instance):
|
||||
return instance.devicebay_count
|
||||
|
||||
|
||||
#
|
||||
# Devices
|
||||
@ -144,6 +153,11 @@ class InterfaceAdmin(admin.TabularInline):
|
||||
model = Interface
|
||||
|
||||
|
||||
class DeviceBayAdmin(admin.TabularInline):
|
||||
model = DeviceBay
|
||||
fk_name = 'device'
|
||||
|
||||
|
||||
class ModuleAdmin(admin.TabularInline):
|
||||
model = Module
|
||||
readonly_fields = ['parent', 'discovered']
|
||||
@ -157,6 +171,7 @@ class DeviceAdmin(admin.ModelAdmin):
|
||||
PowerPortAdmin,
|
||||
PowerOutletAdmin,
|
||||
InterfaceAdmin,
|
||||
DeviceBayAdmin,
|
||||
ModuleAdmin,
|
||||
]
|
||||
list_display = ['display_name', 'device_type', 'device_role', 'primary_ip', 'rack', 'position', 'serial']
|
||||
|
Reference in New Issue
Block a user