mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-24 08:25:17 -06:00
9654 add weight fields to devices
This commit is contained in:
parent
81f0992ace
commit
f55cd6388a
@ -1328,7 +1328,7 @@ class DeviceWeightUnitChoices(ChoiceSet):
|
|||||||
(UNIT_KILOGRAM, 'Kilograms'),
|
(UNIT_KILOGRAM, 'Kilograms'),
|
||||||
(UNIT_GRAM, 'Grams'),
|
(UNIT_GRAM, 'Grams'),
|
||||||
(UNIT_POUND, 'Pounds'),
|
(UNIT_POUND, 'Pounds'),
|
||||||
(UNIT_OUNCE, 'Ounce'),
|
(UNIT_OUNCE, 'Ounces'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -355,12 +355,23 @@ class DeviceTypeBulkEditForm(NetBoxModelBulkEditForm):
|
|||||||
required=False,
|
required=False,
|
||||||
widget=StaticSelect()
|
widget=StaticSelect()
|
||||||
)
|
)
|
||||||
|
weight = forms.DecimalField(
|
||||||
|
min_value=0,
|
||||||
|
required=False
|
||||||
|
)
|
||||||
|
weight_unit = forms.ChoiceField(
|
||||||
|
choices=add_blank_choice(DeviceWeightUnitChoices),
|
||||||
|
required=False,
|
||||||
|
initial='',
|
||||||
|
widget=StaticSelect()
|
||||||
|
)
|
||||||
|
|
||||||
model = DeviceType
|
model = DeviceType
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
(None, ('manufacturer', 'part_number', 'u_height', 'is_full_depth', 'airflow')),
|
(None, ('manufacturer', 'part_number', 'u_height', 'is_full_depth', 'airflow')),
|
||||||
|
('Attributes', ('weight', 'weight_unit')),
|
||||||
)
|
)
|
||||||
nullable_fields = ('part_number', 'airflow')
|
nullable_fields = ('part_number', 'airflow', 'weight')
|
||||||
|
|
||||||
|
|
||||||
class ModuleTypeBulkEditForm(NetBoxModelBulkEditForm):
|
class ModuleTypeBulkEditForm(NetBoxModelBulkEditForm):
|
||||||
|
@ -363,6 +363,7 @@ class DeviceTypeForm(NetBoxModelForm):
|
|||||||
('Chassis', (
|
('Chassis', (
|
||||||
'u_height', 'is_full_depth', 'subdevice_role', 'airflow',
|
'u_height', 'is_full_depth', 'subdevice_role', 'airflow',
|
||||||
)),
|
)),
|
||||||
|
('Attributes', ('weight', 'weight_unit')),
|
||||||
('Images', ('front_image', 'rear_image')),
|
('Images', ('front_image', 'rear_image')),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -370,7 +371,7 @@ class DeviceTypeForm(NetBoxModelForm):
|
|||||||
model = DeviceType
|
model = DeviceType
|
||||||
fields = [
|
fields = [
|
||||||
'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow',
|
'manufacturer', 'model', 'slug', 'part_number', 'u_height', 'is_full_depth', 'subdevice_role', 'airflow',
|
||||||
'front_image', 'rear_image', 'comments', 'tags',
|
'weight', 'weight_unit', 'front_image', 'rear_image', 'comments', 'tags',
|
||||||
]
|
]
|
||||||
widgets = {
|
widgets = {
|
||||||
'subdevice_role': StaticSelect(),
|
'subdevice_role': StaticSelect(),
|
||||||
@ -379,7 +380,8 @@ class DeviceTypeForm(NetBoxModelForm):
|
|||||||
}),
|
}),
|
||||||
'rear_image': ClearableFileInput(attrs={
|
'rear_image': ClearableFileInput(attrs={
|
||||||
'accept': DEVICETYPE_IMAGE_FORMATS
|
'accept': DEVICETYPE_IMAGE_FORMATS
|
||||||
})
|
}),
|
||||||
|
'weight_unit': StaticSelect(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -391,16 +393,20 @@ class ModuleTypeForm(NetBoxModelForm):
|
|||||||
|
|
||||||
fieldsets = (
|
fieldsets = (
|
||||||
('Module Type', (
|
('Module Type', (
|
||||||
'manufacturer', 'model', 'part_number', 'tags',
|
'manufacturer', 'model', 'part_number', 'tags', 'weight', 'weight_unit'
|
||||||
)),
|
)),
|
||||||
)
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ModuleType
|
model = ModuleType
|
||||||
fields = [
|
fields = [
|
||||||
'manufacturer', 'model', 'part_number', 'comments', 'tags',
|
'manufacturer', 'model', 'part_number', 'comments', 'tags', 'weight', 'weight_unit'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
widgets = {
|
||||||
|
'weight_unit': StaticSelect(),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DeviceRoleForm(NetBoxModelForm):
|
class DeviceRoleForm(NetBoxModelForm):
|
||||||
slug = SlugField()
|
slug = SlugField()
|
||||||
|
@ -19,7 +19,7 @@ from utilities.choices import ColorChoices
|
|||||||
from utilities.fields import ColorField, NaturalOrderingField
|
from utilities.fields import ColorField, NaturalOrderingField
|
||||||
from utilities.utils import array_to_string, drange
|
from utilities.utils import array_to_string, drange
|
||||||
from .device_components import PowerOutlet, PowerPort
|
from .device_components import PowerOutlet, PowerPort
|
||||||
from .devices import Device
|
from .devices import Device, Module
|
||||||
from .mixins import DeviceWeightMixin
|
from .mixins import DeviceWeightMixin
|
||||||
from .power import PowerFeed
|
from .power import PowerFeed
|
||||||
|
|
||||||
@ -451,7 +451,8 @@ class Rack(NetBoxModel, DeviceWeightMixin):
|
|||||||
return int(allocated_draw / available_power_total * 100)
|
return int(allocated_draw / available_power_total * 100)
|
||||||
|
|
||||||
def get_total_weight(self):
|
def get_total_weight(self):
|
||||||
total_weight = sum(device._abs_weight for device in self.devices.exclude(_abs_weight__isnull=True))
|
total_weight = sum(device.device_type._abs_weight for device in self.devices.exclude(device_type___abs_weight__isnull=True).prefetch_related('device_type'))
|
||||||
|
total_weight += sum(module.module_type._abs_weight for module in Module.objects.filter(device=self).exclude(module_type___abs_weight__isnull=True).prefetch_related('module_type'))
|
||||||
total_weight += self._abs_weight
|
total_weight += self._abs_weight
|
||||||
return total_weight
|
return total_weight
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user