mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 01:06:11 -06:00
6347 set initial counts for Device in migration
This commit is contained in:
parent
72088adb5c
commit
a1a926f69e
@ -4,6 +4,21 @@ from django.db import migrations
|
|||||||
import utilities.fields
|
import utilities.fields
|
||||||
|
|
||||||
|
|
||||||
|
def recalculate_device_counts(apps, schema_editor):
|
||||||
|
Device = apps.get_model("dcim", "Device")
|
||||||
|
for device in Device.objects.all():
|
||||||
|
device._console_port_count = device.consoleports.count()
|
||||||
|
device._console_server_port_count = device.consoleserverports.count()
|
||||||
|
device._interface_count = device.interfaces.count()
|
||||||
|
device._front_port_count = device.frontports.count()
|
||||||
|
device._rear_port_count = device.rearports.count()
|
||||||
|
device._device_bay_count = device.devicebays.count()
|
||||||
|
device._inventory_item_count = device.inventoryitems.count()
|
||||||
|
device._power_port_count = device.powerports.count()
|
||||||
|
device._power_outlet_count = device.poweroutlets.count()
|
||||||
|
device.save()
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('dcim', '0174_rack_starting_unit'),
|
('dcim', '0174_rack_starting_unit'),
|
||||||
@ -55,4 +70,8 @@ class Migration(migrations.Migration):
|
|||||||
name='_rear_port_count',
|
name='_rear_port_count',
|
||||||
field=utilities.fields.CounterCacheField(default=0),
|
field=utilities.fields.CounterCacheField(default=0),
|
||||||
),
|
),
|
||||||
|
migrations.RunPython(
|
||||||
|
recalculate_device_counts,
|
||||||
|
reverse_code=migrations.RunPython.noop
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
Loading…
Reference in New Issue
Block a user