You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
3.1 KiB
Python
91 lines
3.1 KiB
Python
from django.db import migrations
|
|
|
|
def create_initial_data(apps, schema_editor):
|
|
ContainerKindModel = apps.get_model('common', 'ContainerKindModel')
|
|
ContainerTypeModel = apps.get_model('common', 'ContainerTypeModel')
|
|
CompanyModel = apps.get_model('common', 'CompanyModel')
|
|
LinesModel = apps.get_model('common', 'LinesModel')
|
|
|
|
# Container Kinds
|
|
container_kinds = [
|
|
(1, 'Standart', '', ''),
|
|
(2, 'Reefer', '', ''),
|
|
(3, 'Opentop', '', ''),
|
|
(4, 'FlatRack', '', ''),
|
|
(5, 'Tank', '', ''),
|
|
(6, 'Platform', '', ''),
|
|
]
|
|
for _id, name, *rest in container_kinds:
|
|
ContainerKindModel.objects.create(id=_id, name=name)
|
|
|
|
# Container Types
|
|
container_types = [
|
|
(1, '20GP', 20, False, 1, False),
|
|
(2, '40GP', 40, False, 1, False),
|
|
(3, '40HC', 40, True, 1, False),
|
|
(4, '20RF', 20, False, 2, False),
|
|
(5, '40RF', 40, False, 2, False),
|
|
(6, '20OT', 20, False, 3, False),
|
|
(7, '40OT', 40, False, 3, False),
|
|
(8, '20FR', 20, False, 4, False),
|
|
(9, '20FRPL', 20, False, 6, False),
|
|
(10, '45HC', 45, True, 1, False),
|
|
(11, '40FRPL', 40, False, 6, False),
|
|
(12, '40HR', 40, True, 2, False),
|
|
|
|
]
|
|
for _id, name, length, height, container_type_id, deleted in container_types:
|
|
ContainerTypeModel.objects.create(
|
|
id=_id,
|
|
name=name,
|
|
length=length,
|
|
height=height,
|
|
container_type_id=container_type_id,
|
|
deleted=deleted
|
|
)
|
|
|
|
# Companies and Lines
|
|
companies = [
|
|
(1, 'GMS', 'GMS', 'Global Maritime Servises'),
|
|
(2, 'TO', 'TO', 'Терминален оператор'),
|
|
]
|
|
for _id, name, short_name, description in companies:
|
|
CompanyModel.objects.create(
|
|
id=_id,
|
|
name=name,
|
|
short_name=short_name,
|
|
description=description
|
|
)
|
|
lines = [
|
|
(1, 'GMS', 'GMS', 'GMS line', 1),
|
|
(2, 'HPG', 'HPG', 'Hapag Lloyds line', 1),
|
|
(3, 'TO', 'TO', 'Терминален оператор line', 2),
|
|
]
|
|
for _id, name, short_name, description, company_id in lines:
|
|
LinesModel.objects.create(
|
|
id=_id,
|
|
name=name,
|
|
short_name=short_name,
|
|
description=description,
|
|
company_id=company_id
|
|
)
|
|
|
|
def reverse_initial_data(apps, schema_editor):
|
|
ContainerKindModel = apps.get_model('common', 'ContainerKindModel')
|
|
ContainerTypeModel = apps.get_model('common', 'ContainerTypeModel')
|
|
CompanyModel = apps.get_model('common', 'CompanyModel')
|
|
LinesModel = apps.get_model('common', 'LinesModel')
|
|
|
|
ContainerKindModel.objects.all().delete()
|
|
ContainerTypeModel.objects.all().delete()
|
|
CompanyModel.objects.all().delete()
|
|
LinesModel.objects.all().delete()
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
('common', '0003_auto_20250725_1920'), # Adjust this to your last migration
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(create_initial_data, reverse_initial_data),
|
|
] |