mirror of
https://github.com/nottinghamtec/PyRIGS.git
synced 2026-02-13 18:19:41 +00:00
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
# Generated by Django 2.0.13 on 2019-12-05 13:54
|
|
# Edited by Matthew Smith on same date.
|
|
import re
|
|
from django.db import migrations, models
|
|
|
|
def forwards(apps, schema_editor):
|
|
AssetModel = apps.get_model('assets', 'Asset')
|
|
|
|
for row in AssetModel.objects.all():
|
|
|
|
row.asset_id = row.asset_id.upper()
|
|
asset_search = re.search("^([A-Z0-9]*?[A-Z]?)([0-9]+)$", row.asset_id)
|
|
if asset_search is None: # If the asset_id doesn't have a number at the end
|
|
row.asset_id += "1"
|
|
|
|
asset_search = re.search("^([A-Z0-9]*?[A-Z]?)([0-9]+)$", row.asset_id)
|
|
row.asset_id_prefix = asset_search.group(1)
|
|
row.asset_id_number = int(asset_search.group(2))
|
|
|
|
row.save(update_fields=['asset_id', 'asset_id_prefix', 'asset_id_number'])
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [
|
|
('assets', '0007_auto_20190108_0202_squashed_0014_auto_20191017_2052'),
|
|
]
|
|
|
|
operations = [
|
|
migrations.AddField(
|
|
model_name='asset',
|
|
name='asset_id_number',
|
|
field=models.IntegerField(default=0),
|
|
preserve_default=False,
|
|
),
|
|
migrations.AddField(
|
|
model_name='asset',
|
|
name='asset_id_prefix',
|
|
field=models.CharField(default=0, max_length=5),
|
|
preserve_default=False,
|
|
),
|
|
migrations.RunPython(forwards, reverse_code=migrations.RunPython.noop),
|
|
]
|