1
0
mirror of https://github.com/netbox-community/netbox.git synced 2024-05-10 07:54:54 +00:00
netbox-community-netbox/netbox/dcim/migrations/0079_3569_rack_fields.py

93 lines
2.3 KiB
Python
Raw Normal View History

2019-11-15 21:28:34 -05:00
from django.db import migrations, models
RACK_TYPE_CHOICES = (
(100, '2-post-frame'),
(200, '4-post-frame'),
(300, '4-post-cabinet'),
(1000, 'wall-frame'),
(1100, 'wall-cabinet'),
)
RACK_STATUS_CHOICES = (
(0, 'reserved'),
(1, 'available'),
(2, 'planned'),
(3, 'active'),
(4, 'deprecated'),
)
2019-11-25 20:54:24 -05:00
RACK_DIMENSION_CHOICES = (
(1000, 'mm'),
(2000, 'in'),
)
2019-11-15 21:28:34 -05:00
def rack_type_to_slug(apps, schema_editor):
Rack = apps.get_model('dcim', 'Rack')
for id, slug in RACK_TYPE_CHOICES:
2019-11-15 21:50:33 -05:00
Rack.objects.filter(type=str(id)).update(type=slug)
2019-11-15 21:28:34 -05:00
def rack_status_to_slug(apps, schema_editor):
Rack = apps.get_model('dcim', 'Rack')
for id, slug in RACK_STATUS_CHOICES:
Rack.objects.filter(status=str(id)).update(status=slug)
2019-11-25 20:54:24 -05:00
def rack_outer_unit_to_slug(apps, schema_editor):
Rack = apps.get_model('dcim', 'Rack')
for id, slug in RACK_DIMENSION_CHOICES:
Rack.objects.filter(outer_unit=str(id)).update(outer_unit=slug)
2019-11-25 20:54:24 -05:00
2019-11-15 21:28:34 -05:00
class Migration(migrations.Migration):
atomic = False
2019-11-15 21:28:34 -05:00
dependencies = [
('dcim', '0078_3569_site_fields'),
2019-11-15 21:28:34 -05:00
]
operations = [
# Rack.type
2019-11-15 21:28:34 -05:00
migrations.AlterField(
model_name='rack',
name='type',
2019-11-18 20:54:21 -05:00
field=models.CharField(blank=True, default='', max_length=50),
2019-11-15 21:28:34 -05:00
),
migrations.RunPython(
code=rack_type_to_slug
2019-11-15 22:03:41 -05:00
),
migrations.AlterField(
model_name='rack',
name='type',
field=models.CharField(blank=True, max_length=50),
),
# Rack.status
migrations.AlterField(
model_name='rack',
name='status',
field=models.CharField(default='active', max_length=50),
),
migrations.RunPython(
code=rack_status_to_slug
),
2019-11-25 20:54:24 -05:00
# Rack.outer_unit
migrations.AlterField(
model_name='rack',
name='outer_unit',
field=models.CharField(blank=True, default='', max_length=50),
),
migrations.RunPython(
code=rack_outer_unit_to_slug
),
migrations.AlterField(
model_name='rack',
name='outer_unit',
field=models.CharField(blank=True, max_length=50),
),
2019-12-05 17:42:33 -05:00
2019-11-15 21:28:34 -05:00
]