from django.core.management.base import BaseCommand from product.models import ProductType, ProductSubType def add_type(): product_type = ProductType.objects.create( name={'"en-GB"': "Wine"}, index_name=ProductType.WINE ) return product_type.save() def add_subtype(id_type): subtypes = ProductSubType.objects.bulk_create([ ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.EXTRA_BRUT}, index_name=ProductSubType.EXTRA_BRUT), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.BRUT}, index_name=ProductSubType.BRUT), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.BRUT_NATURE}, index_name=ProductSubType.BRUT_NATURE), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.DEMI_SEC}, index_name=ProductSubType.DEMI_SEC), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.EXTRA_DRY}, index_name=ProductSubType.EXTRA_DRY), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.DOSAGE_ZERO}, index_name=ProductSubType.DOSAGE_ZERO), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.SEC}, index_name=ProductSubType.SEC), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.SEC}, index_name=ProductSubType.SEC), ProductSubType(product_type=id_type, name={"en-GB", ProductSubType.MOELLEUX}, index_name=ProductSubType.MOELLEUX), ]) class Command(BaseCommand): help = 'Add product data' def handle(self, *args, **kwarg): product_type = add_type() add_subtype(product_type.id)