mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-21 22:09:42 +00:00
Move relevant fields and create migration to autogen cable types
This commit is contained in:
26
assets/migrations/0012_auto_20200218_1627.py
Normal file
26
assets/migrations/0012_auto_20200218_1627.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Generated by Django 2.0.13 on 2020-02-18 16:27
|
||||
|
||||
from django.db import migrations
|
||||
from django.db.models import Q
|
||||
|
||||
|
||||
def move_cable_type_data(apps, schema_editor):
|
||||
Asset = apps.get_model('assets', 'Asset')
|
||||
CableType = apps.get_model('assets', 'CableType')
|
||||
for asset in Asset.objects.filter(is_cable=True):
|
||||
# Only create one type per...well...type
|
||||
if(not CableType.objects.filter(Q(plug=asset.plug) & Q(socket=asset.socket))):
|
||||
cabletype = CableType.objects.create(plug=asset.plug, socket=asset.socket, circuits=asset.circuits, cores=asset.cores)
|
||||
asset.save()
|
||||
cabletype.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('assets', '0011_auto_20200218_1617'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(move_cable_type_data)
|
||||
]
|
||||
Reference in New Issue
Block a user