# Generated by Django 4.0 on 2021-12-13 17:54

from django.db import migrations

_CAR_GOODS = 'Автотовары'
_APPLIANCES = 'Бытовая техника'


def _create_categories(apps, schema_editor) -> None:
    """Создает две категории"""

    # noinspection PyPep8Naming
    Category = apps.get_model('shop', 'Category')

    Category.objects.get_or_create(name=_CAR_GOODS)
    Category.objects.get_or_create(name=_APPLIANCES)


def _create_products(apps, schema_editor) -> None:
    """Создает два товара"""

    # noinspection PyPep8Naming
    Product = apps.get_model('shop', 'Product')
    # noinspection PyPep8Naming
    Category = apps.get_model('shop', 'Category')

    Product.objects.get_or_create(
        name='Зимняя резина',
        category=Category.objects.get(name=_CAR_GOODS),
        price=4990.00,
    )
    Product.objects.get_or_create(
        name='Холодильник',
        category=Category.objects.get(name=_APPLIANCES),
        price=49990.00,
    )


class Migration(migrations.Migration):
    dependencies = [
        ('shop', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(
            code=_create_categories,
            reverse_code=migrations.RunPython.noop,
        ),
        migrations.RunPython(
            code=_create_products,
            reverse_code=migrations.RunPython.noop,
        ),
    ]

# Generated by Django 4.0 on 2021-12-13 17:54

from django.db import migrations

_CAR_GOODS = 'Автотовары'
_APPLIANCES = 'Бытовая техника'


def _create_categories(apps, schema_editor) -> None:
    """Создает две категории"""

    # noinspection PyPep8Naming
    Category = apps.get_model('shop', 'Category')

    Category.objects.get_or_create(name=_CAR_GOODS)
    Category.objects.get_or_create(name=_APPLIANCES)


def _create_products(apps, schema_editor) -> None:
    """Создает два товара"""

    # noinspection PyPep8Naming
    Product = apps.get_model('shop', 'Product')
    # noinspection PyPep8Naming
    Category = apps.get_model('shop', 'Category')

    Product.objects.get_or_create(
        name='Зимняя резина',
        category=Category.objects.get(name=_CAR_GOODS),
        price=4990.00,
    )
    Product.objects.get_or_create(
        name='Холодильник',
        category=Category.objects.get(name=_APPLIANCES),
        price=49990.00,
    )


class Migration(migrations.Migration):
    dependencies = [
        ('shop', '0001_initial'),
    ]

    operations = [
        migrations.RunPython(
            code=_create_categories,
            reverse_code=migrations.RunPython.noop,
        ),
        migrations.RunPython(
            code=_create_products,
            reverse_code=migrations.RunPython.noop,
        ),
    ]

# Generated by Django 4.0 on 2021-12-13 17:54 Создает две категории # noinspection PyPep8Naming Создает два товара # noinspection PyPep8Naming # noinspection PyPep8Naming