<filename>shop/migrations/0020_installmentoption.py
# Generated by Django 3.1 on 2020-08-05 16:50

import django.core.validators
from django.db import migrations, models

from shop.utils import create_installment_code
from thebrushstash.constants import initial_installment_options


def add_initial_installment_options(apps, schema_editor):
    InstallmentOption = apps.get_model('shop', 'InstallmentOption')

    for installment_option in initial_installment_options:
        obj, _ = InstallmentOption.objects.update_or_create(
            range_from=installment_option['range_from'],
            range_to=installment_option['range_to'],
            installment_number=installment_option['installment_number'],
        )
        create_installment_code(obj)


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0019_auto_20200731_1832'),
    ]

    operations = [
        migrations.CreateModel(
            name='InstallmentOption',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('range_from', models.DecimalField(decimal_places=2, max_digits=15)),
                ('range_to', models.DecimalField(decimal_places=2, max_digits=15)),
                ('installment_number', models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(2), django.core.validators.MaxValueValidator(36)])),
                ('installment_code', models.CharField(blank=True, max_length=5)),
            ],
            options={
                'verbose_name': 'Installment option',
                'verbose_name_plural': 'Installment options',
            },
        ),
        migrations.RunPython(
            code=add_initial_installment_options,
            reverse_code=migrations.operations.special.RunPython.noop,
        ),
    ]

<filename>shop/migrations/0020_installmentoption.py
# Generated by Django 3.1 on 2020-08-05 16:50

import django.core.validators
from django.db import migrations, models

from shop.utils import create_installment_code
from thebrushstash.constants import initial_installment_options


def add_initial_installment_options(apps, schema_editor):
    InstallmentOption = apps.get_model('shop', 'InstallmentOption')

    for installment_option in initial_installment_options:
        obj, _ = InstallmentOption.objects.update_or_create(
            range_from=installment_option['range_from'],
            range_to=installment_option['range_to'],
            installment_number=installment_option['installment_number'],
        )
        create_installment_code(obj)


class Migration(migrations.Migration):

    dependencies = [
        ('shop', '0019_auto_20200731_1832'),
    ]

    operations = [
        migrations.CreateModel(
            name='InstallmentOption',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('created_at', models.DateTimeField(auto_now_add=True)),
                ('modified_at', models.DateTimeField(auto_now=True)),
                ('range_from', models.DecimalField(decimal_places=2, max_digits=15)),
                ('range_to', models.DecimalField(decimal_places=2, max_digits=15)),
                ('installment_number', models.PositiveSmallIntegerField(validators=[django.core.validators.MinValueValidator(2), django.core.validators.MaxValueValidator(36)])),
                ('installment_code', models.CharField(blank=True, max_length=5)),
            ],
            options={
                'verbose_name': 'Installment option',
                'verbose_name_plural': 'Installment options',
            },
        ),
        migrations.RunPython(
            code=add_initial_installment_options,
            reverse_code=migrations.operations.special.RunPython.noop,
        ),
    ]

# Generated by Django 3.1 on 2020-08-05 16:50