Add product migrate data

This commit is contained in:
Виктор Гладких 2019-10-30 18:04:30 +03:00
parent f6151c0a14
commit c1c9f99fb5
3 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,54 @@
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)

View File

@ -46,10 +46,28 @@ class ProductSubType(TranslatedFieldsMixin, ProjectBaseMixin):
# INDEX NAME CHOICES
RUM = 'rum'
OTHER = 'other'
EXTRA_BRUT = 'extra brut'
BRUT = 'brut'
BRUT_NATURE = 'brut nature'
DEMI_SEC = 'demi-sec'
EXTRA_DRY = 'Extra Dry'
DOSAGE_ZERO = 'dosage zero'
SEC = 'sec'
DOUX = 'doux'
MOELLEUX= 'moelleux'
INDEX_NAME_TYPES = (
(RUM, _('Rum')),
(OTHER, _('Other')),
(EXTRA_BRUT, _('extra brut')),
(BRUT, _('brut')),
(BRUT_NATURE, _('brut nature')),
(DEMI_SEC, _('demi-sec')),
(EXTRA_DRY, _('Extra Dry')),
(DOSAGE_ZERO, _('dosage zero')),
(SEC, _('sec')),
(DOUX, _('doux')),
(MOELLEUX, _('moelleux'))
)
product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE,

View File

@ -842,6 +842,7 @@ class Ads(MigrateMixin):
managed = False
db_table = 'ads'
class Products(models.Model):
establishment = models.ForeignKey('Establishments', models.DO_NOTHING, blank=True, null=True)
brand = models.CharField(max_length=255, blank=True, null=True)