mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
* Update serializers.py * Update vlans.py * Update vlans.py * Update vlangroup.html * Update vlans.py * Update vlans.py * Update serializers.py * adds db annotation to calculate utilization * optimize queries * merge fix * adds round function for utilization to limit decimal * fixed object view annotation * consolidated queryset for utilization * lint fixes * Renamed manager method to annotate_utilization() for consistency with other managers --------- Co-authored-by: Abhimanyu Saharan <desk.abhimanyu@gmail.com>
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.db.models import Count, OuterRef, Q, Subquery, Value
|
||||
from django.db.models import Count, F, OuterRef, Q, Subquery, Value
|
||||
from django.db.models.expressions import RawSQL
|
||||
from django.db.models.functions import Round
|
||||
|
||||
from utilities.querysets import RestrictedQuerySet
|
||||
from utilities.utils import count_related
|
||||
|
||||
__all__ = (
|
||||
'ASNRangeQuerySet',
|
||||
@@ -54,6 +56,17 @@ class PrefixQuerySet(RestrictedQuerySet):
|
||||
)
|
||||
|
||||
|
||||
class VLANGroupQuerySet(RestrictedQuerySet):
|
||||
|
||||
def annotate_utilization(self):
|
||||
from .models import VLAN
|
||||
|
||||
return self.annotate(
|
||||
vlan_count=count_related(VLAN, 'group'),
|
||||
utilization=Round(F('vlan_count') / (F('max_vid') - F('min_vid') + 1.0) * 100, 2)
|
||||
)
|
||||
|
||||
|
||||
class VLANQuerySet(RestrictedQuerySet):
|
||||
|
||||
def get_for_device(self, device):
|
||||
|
Reference in New Issue
Block a user