# -*- coding: utf-8 -*- # Generated by Django 1.11.10 on 2018-08-09 11:52 from __future__ import unicode_literals import django.core.validators from django.db import migrations, models import django.db.models.deletion import ishtar_common.models import re def migrate_operation(apps, schema_editor): Operation = apps.get_model('archaeological_operations', 'Operation') RecordQualityType = apps.get_model('archaeological_operations', 'RecordQualityType') not_documented, c = RecordQualityType.objects.get_or_create( txt_idx=u"not-documented", defaults={ "label": u"Non documenté", "order": 10 } ) arbitrary, c = RecordQualityType.objects.get_or_create( txt_idx=u"arbitrary", defaults={ "label": u"Arbitraire", "order": 20 } ) reliable, c = RecordQualityType.objects.get_or_create( txt_idx=u"reliable", defaults={ "label": u"Fiable", "order": 30 } ) QUALITY = { 'ND': not_documented, 'A': arbitrary, 'R': reliable } for operation in Operation.objects.all(): if not operation.record_quality: continue if operation.record_quality not in QUALITY: continue operation.record_quality_type = QUALITY[operation.record_quality] operation.skip_history_when_saving = True operation.save() class Migration(migrations.Migration): dependencies = [ ('archaeological_operations', '0034_archaeologicalsite_cached_label'), ] operations = [ migrations.CreateModel( name='RecordQualityType', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('label', models.TextField(verbose_name='Label')), ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z'), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')), ('comment', models.TextField(blank=True, null=True, verbose_name='Comment')), ('available', models.BooleanField(default=True, verbose_name='Available')), ('order', models.IntegerField(verbose_name='Order')), ], options={ 'ordering': ('order',), 'verbose_name': 'Type of record quality', 'verbose_name_plural': 'Types of record quality', }, bases=(ishtar_common.models.Cached, models.Model), ), migrations.AddField( model_name='historicaloperation', name='record_quality_type', field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_operations.RecordQualityType'), ), migrations.AddField( model_name='operation', name='record_quality_type', field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='archaeological_operations.RecordQualityType', verbose_name='Record quality'), ), migrations.RunPython(migrate_operation), ]