mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-26 01:06:11 -06:00
6347 update ref to parent_model, migration
This commit is contained in:
parent
07a1d049a1
commit
52d6e8f9e4
@ -1,28 +1,12 @@
|
|||||||
# Generated by Django 4.1.8 on 2023-05-16 20:18
|
# Generated by Django 4.2.2 on 2023-06-23 19:26
|
||||||
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
import utilities.fields
|
import utilities.fields
|
||||||
|
|
||||||
|
|
||||||
def populate_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', '0173_remove_napalm_fields'),
|
('dcim', '0174_rack_starting_unit'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@ -71,8 +55,4 @@ 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(
|
|
||||||
code=populate_device_counts,
|
|
||||||
reverse_code=migrations.RunPython.noop
|
|
||||||
),
|
|
||||||
]
|
]
|
@ -35,7 +35,7 @@ class Counter(object):
|
|||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"{self.counter_name} should be a CounterCacheField on {self.parent_model}, but is {type(counter_field)}"
|
f"{self.counter_name} should be a CounterCacheField on {self.parent_model}, but is {type(counter_field)}"
|
||||||
)
|
)
|
||||||
if not isinstance(parent_model, TrackingModelMixin):
|
if not isinstance(self.parent_model, TrackingModelMixin):
|
||||||
raise TypeError(
|
raise TypeError(
|
||||||
f"{self.parent_model} should be derived from TrackingModelMixin"
|
f"{self.parent_model} should be derived from TrackingModelMixin"
|
||||||
)
|
)
|
||||||
|
@ -9,6 +9,7 @@ from .validators import ColorValidator
|
|||||||
|
|
||||||
__all__ = (
|
__all__ = (
|
||||||
'ColorField',
|
'ColorField',
|
||||||
|
'CounterCacheField',
|
||||||
'NaturalOrderingField',
|
'NaturalOrderingField',
|
||||||
'NullableCharField',
|
'NullableCharField',
|
||||||
'RestrictedGenericForeignKey',
|
'RestrictedGenericForeignKey',
|
||||||
|
Loading…
Reference in New Issue
Block a user