mirror of
				https://github.com/netbox-community/netbox.git
				synced 2024-05-10 07:54:54 +00:00 
			
		
		
		
	Closes #6109: Add device counts to locations table
This commit is contained in:
		@@ -2,6 +2,10 @@
 | 
			
		||||
 | 
			
		||||
## v2.11.0 (FUTURE)
 | 
			
		||||
 | 
			
		||||
### Enhancements (from Beta)
 | 
			
		||||
 | 
			
		||||
* [#6109](https://github.com/netbox-community/netbox/issues/6109) - Add device counts to locations table
 | 
			
		||||
 | 
			
		||||
### Bug Fixes (from Beta)
 | 
			
		||||
 | 
			
		||||
* [#6100](https://github.com/netbox-community/netbox/issues/6100) - Fix VM interfaces table "add interfaces" link
 | 
			
		||||
 
 | 
			
		||||
@@ -1,49 +1,21 @@
 | 
			
		||||
import django_tables2 as tables
 | 
			
		||||
from django_tables2.utils import Accessor
 | 
			
		||||
 | 
			
		||||
from dcim.models import Rack, Location, RackReservation, RackRole
 | 
			
		||||
from dcim.models import Rack, RackReservation, RackRole
 | 
			
		||||
from tenancy.tables import TenantColumn
 | 
			
		||||
from utilities.tables import (
 | 
			
		||||
    BaseTable, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn, MPTTColumn,
 | 
			
		||||
    TagColumn, ToggleColumn, UtilizationColumn,
 | 
			
		||||
    BaseTable, ButtonsColumn, ChoiceFieldColumn, ColorColumn, ColoredLabelColumn, LinkedCountColumn, TagColumn,
 | 
			
		||||
    ToggleColumn, UtilizationColumn,
 | 
			
		||||
)
 | 
			
		||||
from .template_code import LOCATION_ELEVATIONS
 | 
			
		||||
 | 
			
		||||
__all__ = (
 | 
			
		||||
    'RackTable',
 | 
			
		||||
    'RackDetailTable',
 | 
			
		||||
    'LocationTable',
 | 
			
		||||
    'RackReservationTable',
 | 
			
		||||
    'RackRoleTable',
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Locations
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
class LocationTable(BaseTable):
 | 
			
		||||
    pk = ToggleColumn()
 | 
			
		||||
    name = MPTTColumn(
 | 
			
		||||
        linkify=True
 | 
			
		||||
    )
 | 
			
		||||
    site = tables.Column(
 | 
			
		||||
        linkify=True
 | 
			
		||||
    )
 | 
			
		||||
    rack_count = tables.Column(
 | 
			
		||||
        verbose_name='Racks'
 | 
			
		||||
    )
 | 
			
		||||
    actions = ButtonsColumn(
 | 
			
		||||
        model=Location,
 | 
			
		||||
        prepend_template=LOCATION_ELEVATIONS
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    class Meta(BaseTable.Meta):
 | 
			
		||||
        model = Location
 | 
			
		||||
        fields = ('pk', 'name', 'site', 'rack_count', 'description', 'slug', 'actions')
 | 
			
		||||
        default_columns = ('pk', 'name', 'site', 'rack_count', 'description', 'actions')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Rack roles
 | 
			
		||||
#
 | 
			
		||||
 
 | 
			
		||||
@@ -1,12 +1,14 @@
 | 
			
		||||
import django_tables2 as tables
 | 
			
		||||
 | 
			
		||||
from dcim.models import Region, Site, SiteGroup
 | 
			
		||||
from dcim.models import Location, Region, Site, SiteGroup
 | 
			
		||||
from tenancy.tables import TenantColumn
 | 
			
		||||
from utilities.tables import (
 | 
			
		||||
    BaseTable, ButtonsColumn, ChoiceFieldColumn, LinkedCountColumn, MPTTColumn, TagColumn, ToggleColumn,
 | 
			
		||||
)
 | 
			
		||||
from .template_code import LOCATION_ELEVATIONS
 | 
			
		||||
 | 
			
		||||
__all__ = (
 | 
			
		||||
    'LocationTable',
 | 
			
		||||
    'RegionTable',
 | 
			
		||||
    'SiteTable',
 | 
			
		||||
    'SiteGroupTable',
 | 
			
		||||
@@ -86,3 +88,32 @@ class SiteTable(BaseTable):
 | 
			
		||||
            'contact_email', 'tags',
 | 
			
		||||
        )
 | 
			
		||||
        default_columns = ('pk', 'name', 'status', 'facility', 'region', 'group', 'tenant', 'asn', 'description')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Locations
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
class LocationTable(BaseTable):
 | 
			
		||||
    pk = ToggleColumn()
 | 
			
		||||
    name = MPTTColumn(
 | 
			
		||||
        linkify=True
 | 
			
		||||
    )
 | 
			
		||||
    site = tables.Column(
 | 
			
		||||
        linkify=True
 | 
			
		||||
    )
 | 
			
		||||
    rack_count = tables.Column(
 | 
			
		||||
        verbose_name='Racks'
 | 
			
		||||
    )
 | 
			
		||||
    device_count = tables.Column(
 | 
			
		||||
        verbose_name='Devices'
 | 
			
		||||
    )
 | 
			
		||||
    actions = ButtonsColumn(
 | 
			
		||||
        model=Location,
 | 
			
		||||
        prepend_template=LOCATION_ELEVATIONS
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    class Meta(BaseTable.Meta):
 | 
			
		||||
        model = Location
 | 
			
		||||
        fields = ('pk', 'name', 'site', 'rack_count', 'device_count', 'description', 'slug', 'actions')
 | 
			
		||||
        default_columns = ('pk', 'name', 'site', 'rack_count', 'device_count', 'description', 'actions')
 | 
			
		||||
 
 | 
			
		||||
@@ -338,12 +338,18 @@ class SiteBulkDeleteView(generic.BulkDeleteView):
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
# Rack groups
 | 
			
		||||
# Locations
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
class LocationListView(generic.ObjectListView):
 | 
			
		||||
    queryset = Location.objects.add_related_count(
 | 
			
		||||
        Location.objects.all(),
 | 
			
		||||
        Location.objects.add_related_count(
 | 
			
		||||
            Location.objects.all(),
 | 
			
		||||
            Device,
 | 
			
		||||
            'location',
 | 
			
		||||
            'device_count',
 | 
			
		||||
            cumulative=True
 | 
			
		||||
        ),
 | 
			
		||||
        Rack,
 | 
			
		||||
        'location',
 | 
			
		||||
        'rack_count',
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user