from django.db import migrations # Offsets are 0-based. The %p scale's original Delphi used 1-based Copy(s, 5, 8), # i.e. the 5th character onward - which is index 4 here. PROTOCOLS = [ { 'name': 'Simulator (ST/US)', 'kind': 'simulator', 'poll_command': '', 'poll_interval': 0.2, 'config': {}, }, { 'name': 'Fixed column 22-char (%p)', 'kind': 'fixed_column', 'poll_command': '%p', 'poll_interval': 0.2, 'config': { 'weight_start': 4, 'weight_length': 8, 'stable_pos': 21, 'stable_char': ' ', 'stable_means_balanced': True, 'decimals': 0, }, }, { 'name': 'Toledo Continuous', 'kind': 'toledo_continuous', 'poll_command': '', 'poll_interval': 0.2, 'config': {}, }, { 'name': 'Mettler-Toledo SICS', 'kind': 'sics', 'poll_command': 'SI', 'poll_interval': 0.2, 'config': {}, }, ] def seed(apps, schema_editor): ScaleProtocol = apps.get_model('api', 'ScaleProtocol') for entry in PROTOCOLS: ScaleProtocol.objects.update_or_create( name=entry['name'], defaults=dict(entry, is_builtin=True, is_active=True), ) def unseed(apps, schema_editor): ScaleProtocol = apps.get_model('api', 'ScaleProtocol') ScaleProtocol.objects.filter( name__in=[e['name'] for e in PROTOCOLS], is_builtin=True ).delete() class Migration(migrations.Migration): dependencies = [ ('api', '0006_scaleprotocol'), ] operations = [ migrations.RunPython(seed, unseed), ]