mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-24 17:38:37 -06:00
Location model cleanup
This commit is contained in:
parent
4883bc3dd4
commit
7b8bd2d4ce
@ -134,12 +134,13 @@ class LocationSerializer(NestedGroupModelSerializer):
|
|||||||
site = NestedSiteSerializer()
|
site = NestedSiteSerializer()
|
||||||
parent = NestedLocationSerializer(required=False, allow_null=True)
|
parent = NestedLocationSerializer(required=False, allow_null=True)
|
||||||
rack_count = serializers.IntegerField(read_only=True)
|
rack_count = serializers.IntegerField(read_only=True)
|
||||||
|
device_count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Location
|
model = Location
|
||||||
fields = [
|
fields = [
|
||||||
'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'description', 'custom_fields', 'created',
|
'id', 'url', 'display', 'name', 'slug', 'site', 'parent', 'description', 'custom_fields', 'created',
|
||||||
'last_updated', 'rack_count', '_depth',
|
'last_updated', 'rack_count', 'device_count', '_depth',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,7 +146,13 @@ class SiteViewSet(CustomFieldModelViewSet):
|
|||||||
|
|
||||||
class LocationViewSet(CustomFieldModelViewSet):
|
class LocationViewSet(CustomFieldModelViewSet):
|
||||||
queryset = Location.objects.add_related_count(
|
queryset = Location.objects.add_related_count(
|
||||||
Location.objects.all(),
|
Location.objects.add_related_count(
|
||||||
|
Location.objects.all(),
|
||||||
|
Device,
|
||||||
|
'location',
|
||||||
|
'device_count',
|
||||||
|
cumulative=True
|
||||||
|
),
|
||||||
Rack,
|
Rack,
|
||||||
'location',
|
'location',
|
||||||
'rack_count',
|
'rack_count',
|
||||||
@ -174,7 +180,7 @@ class RackRoleViewSet(CustomFieldModelViewSet):
|
|||||||
|
|
||||||
class RackViewSet(CustomFieldModelViewSet):
|
class RackViewSet(CustomFieldModelViewSet):
|
||||||
queryset = Rack.objects.prefetch_related(
|
queryset = Rack.objects.prefetch_related(
|
||||||
'site', 'location__site', 'role', 'tenant', 'tags'
|
'site', 'location', 'role', 'tenant', 'tags'
|
||||||
).annotate(
|
).annotate(
|
||||||
device_count=count_related(Device, 'rack'),
|
device_count=count_related(Device, 'rack'),
|
||||||
powerfeed_count=count_related(PowerFeed, 'rack')
|
powerfeed_count=count_related(PowerFeed, 'rack')
|
||||||
|
@ -315,6 +315,7 @@ class Location(NestedGroupModel):
|
|||||||
)
|
)
|
||||||
|
|
||||||
csv_headers = ['site', 'parent', 'name', 'slug', 'description']
|
csv_headers = ['site', 'parent', 'name', 'slug', 'description']
|
||||||
|
clone_fields = ['site', 'parent', 'description']
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
ordering = ['site', 'name']
|
ordering = ['site', 'name']
|
||||||
|
@ -272,6 +272,13 @@ class SiteView(generic.ObjectView):
|
|||||||
'location',
|
'location',
|
||||||
'rack_count',
|
'rack_count',
|
||||||
cumulative=True
|
cumulative=True
|
||||||
|
)
|
||||||
|
locations = Location.objects.add_related_count(
|
||||||
|
locations,
|
||||||
|
Device,
|
||||||
|
'location',
|
||||||
|
'device_count',
|
||||||
|
cumulative=True
|
||||||
).restrict(request.user, 'view').filter(site=instance)
|
).restrict(request.user, 'view').filter(site=instance)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
<td>Description</td>
|
<td>Description</td>
|
||||||
<td>{{ object.description|placeholder }}</td>
|
<td>{{ object.description|placeholder }}</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>Site</td>
|
||||||
|
<td><a href="{{ object.site.get_absolute_url }}">{{ object.site }}</a></td>
|
||||||
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>Parent</td>
|
<td>Parent</td>
|
||||||
<td>
|
<td>
|
||||||
|
@ -210,12 +210,22 @@
|
|||||||
<strong>Locations</strong>
|
<strong>Locations</strong>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-hover panel-body">
|
<table class="table table-hover panel-body">
|
||||||
|
<tr>
|
||||||
|
<th>Location</th>
|
||||||
|
<th>Racks</th>
|
||||||
|
<th>Devices</th>
|
||||||
|
<th></th>
|
||||||
|
</tr>
|
||||||
{% for location in locations %}
|
{% for location in locations %}
|
||||||
<tr>
|
<tr>
|
||||||
<td style="padding-left: {{ location.level }}8px">
|
<td style="padding-left: {{ location.level }}8px">
|
||||||
<i class="mdi mdi-folder-open"></i> <a href="{{ location.get_absolute_url }}">{{ location }}</a>
|
<i class="mdi mdi-folder-open-outline"></i> <a href="{{ location.get_absolute_url }}">{{ location }}</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'dcim:rack_list' %}?location_id={{ location.pk }}">{{ location.rack_count }}</a></td>
|
||||||
|
<td>
|
||||||
|
<a href="{% url 'dcim:device_list' %}?location_id={{ location.pk }}">{{ location.device_count }}</a>
|
||||||
</td>
|
</td>
|
||||||
<td>{{ location.rack_count }}</td>
|
|
||||||
<td class="text-right noprint">
|
<td class="text-right noprint">
|
||||||
<a href="{% url 'dcim:rack_elevation_list' %}?location_id={{ location.pk }}" class="btn btn-xs btn-primary" title="View elevations">
|
<a href="{% url 'dcim:rack_elevation_list' %}?location_id={{ location.pk }}" class="btn btn-xs btn-primary" title="View elevations">
|
||||||
<i class="mdi mdi-server"></i>
|
<i class="mdi mdi-server"></i>
|
||||||
@ -223,15 +233,6 @@
|
|||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
<tr>
|
|
||||||
<td><i class="mdi mdi-folder-open"></i> All racks</td>
|
|
||||||
<td>{{ stats.rack_count }}</td>
|
|
||||||
<td class="text-right noprint">
|
|
||||||
<a href="{% url 'dcim:rack_elevation_list' %}?site_id={{ object.pk }}" class="btn btn-xs btn-primary" title="View elevations">
|
|
||||||
<i class="mdi mdi-server"></i>
|
|
||||||
</a>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
|
Loading…
Reference in New Issue
Block a user