Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Generate different categories in populatedb

Marcin Gębaladd5440538b4a
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index 3be8c995c4..75ef60dd3d 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -23,10 +23,13 @@ from ...userprofile.models import Address, User
fake = Factory.create()
STOCK_LOCATION = 'default'
+DEFAULT_CATEGORY = 'Default'
+
DELIVERY_REGIONS = [ANY_COUNTRY, 'US', 'PL', 'DE', 'GB']
DEFAULT_SCHEMA = {
'T-Shirt': {
+ 'category': 'Apparel',
'product_attributes': {
'Color': ['Blue', 'White'],
'Collar': ['Round', 'V-Neck', 'Polo'],
@@ -38,6 +41,7 @@ DEFAULT_SCHEMA = {
'images_dir': 't-shirts/',
},
'Mugs': {
+ 'category': 'Accessories',
'product_attributes': {
'Brand': ['Saleor']
},
@@ -45,6 +49,7 @@ DEFAULT_SCHEMA = {
'images_dir': 'mugs/'
},
'Coffee': {
+ 'category': 'Foodstuffs',
'product_attributes': {
'Coffee Genre': ['Arabica', 'Robusta'],
'Brand': ['Saleor']
@@ -56,6 +61,7 @@ DEFAULT_SCHEMA = {
'images_dir': 'coffee/',
},
'Candy': {
+ 'category': 'Foodstuffs',
'product_attributes': {
'Flavor': ['Sour', 'Sweet'],
'Brand': ['Saleor']
@@ -154,12 +160,13 @@ def get_price_override(schema):
def create_items_by_class(product_class, schema,
placeholder_dir, how_many=10, create_images=True,
stdout=None):
- default_category = get_or_create_category('Default')
+ category_name = schema.get('category') or DEFAULT_CATEGORY
+ category = get_or_create_category(category_name)
for dummy in range(how_many):
product = create_product(product_class=product_class)
set_product_attributes(product, product_class)
- product.categories.add(default_category)
+ product.categories.add(category)
if create_images:
class_placeholders = os.path.join(
placeholder_dir, schema['images_dir'])