mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-08 00:28:16 -06:00
17032 Convert Virtual Disk size from GB -> MB
This commit is contained in:
parent
954eadcdc5
commit
30003bee98
@ -29,7 +29,7 @@
|
||||
<th scope="row"><i class="mdi mdi-harddisk"></i> {% trans "Size" %}</th>
|
||||
<td>
|
||||
{% if object.size %}
|
||||
{{ object.size }} {% trans "GB" context "Abbreviation for gigabyte" %}
|
||||
{{ object.size|humanize_megabytes }}
|
||||
{% else %}
|
||||
{{ ''|placeholder }}
|
||||
{% endif %}
|
||||
|
23
netbox/virtualization/migrations/0041_convert_disk_size.py
Normal file
23
netbox/virtualization/migrations/0041_convert_disk_size.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 5.0.7 on 2024-07-31 05:40
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.models import F
|
||||
|
||||
|
||||
def convert_disk_size(apps, schema_editor):
|
||||
VirtualDisk = apps.get_model('virtualization', 'VirtualDisk')
|
||||
VirtualDisk.objects.filter(disk__isnull=False).update(disk=F('size') * 1000)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('virtualization', '0040_virtualmachine_serial_number'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(
|
||||
code=convert_disk_size,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
@ -431,7 +431,7 @@ class VMInterface(ComponentModel, BaseInterface, TrackingModelMixin):
|
||||
|
||||
class VirtualDisk(ComponentModel, TrackingModelMixin):
|
||||
size = models.PositiveIntegerField(
|
||||
verbose_name=_('size (GB)'),
|
||||
verbose_name=_('size (MB)'),
|
||||
)
|
||||
|
||||
class Meta(ComponentModel.Meta):
|
||||
|
@ -208,6 +208,9 @@ class VirtualDiskTable(NetBoxTable):
|
||||
'data-name': lambda record: record.name,
|
||||
}
|
||||
|
||||
def render_size(self, value):
|
||||
return humanize_megabytes(value)
|
||||
|
||||
|
||||
class VirtualMachineVirtualDiskTable(VirtualDiskTable):
|
||||
actions = columns.ActionsColumn(
|
||||
@ -219,3 +222,6 @@ class VirtualMachineVirtualDiskTable(VirtualDiskTable):
|
||||
'pk', 'id', 'name', 'size', 'description', 'tags', 'actions',
|
||||
)
|
||||
default_columns = ('pk', 'name', 'size', 'description')
|
||||
|
||||
def render_size(self, value):
|
||||
return humanize_megabytes(value)
|
||||
|
Loading…
Reference in New Issue
Block a user