Skip to content

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

Add generating collection to populatedb

akjanikb0587eecc302
diff --git a/saleor/core/management/commands/populatedb.py b/saleor/core/management/commands/populatedb.py
index c05bdfa978..673e78b2cf 100644
--- a/saleor/core/management/commands/populatedb.py
+++ b/saleor/core/management/commands/populatedb.py
@@ -5,9 +5,9 @@ from django.db import connection
from ...utils import create_superuser
from ...utils.random_data import (
- add_address_to_admin, create_groups, create_orders, create_product_sales,
- create_products_by_schema, create_shipping_methods, create_users,
- create_vouchers, set_featured_products)
+ add_address_to_admin, create_collections, create_groups, create_orders,
+ create_product_sales, create_products_by_schema, create_shipping_methods,
+ create_users, create_vouchers, set_featured_products)
class Command(BaseCommand):
@@ -66,6 +66,8 @@ class Command(BaseCommand):
self.stdout.write(msg)
for msg in set_featured_products(16):
self.stdout.write(msg)
+ for msg in create_collections(2):
+ self.stdout.write(msg)
self.stdout.write(create_groups())
if options['createsuperuser']:
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.py
index e74bf9ee7d..31dd36ad1e 100644
--- a/saleor/core/utils/random_data.py
+++ b/saleor/core/utils/random_data.py
@@ -18,8 +18,8 @@ from ...discount.models import Sale, Voucher
from ...order import GroupStatus
from ...order.models import DeliveryGroup, Order, OrderLine, Payment
from ...product.models import (
- AttributeChoiceValue, Category, Product, ProductAttribute, ProductImage,
- ProductType, ProductVariant, Stock, StockLocation)
+ AttributeChoiceValue, Category, Collection, Product, ProductAttribute,
+ ProductImage, ProductType, ProductVariant, Stock, StockLocation)
from ...shipping.models import ANY_COUNTRY, ShippingMethod
from ...userprofile.models import Address, User
from ...userprofile.utils import store_user_address
@@ -262,6 +262,11 @@ def get_or_create_product_type(name, **kwargs):
return ProductType.objects.get_or_create(name=name, defaults=kwargs)[0]
+def get_or_create_collection(name, **kwargs):
+ kwargs['slug'] = fake.slug(name)
+ return Collection.objects.get_or_create(name=name, defaults=kwargs)[0]
+
+
def create_product(**kwargs):
defaults = {
'name': fake.company(),
@@ -533,3 +538,16 @@ def add_address_to_admin(email):
address = create_address()
user = User.objects.get(email=email)
store_user_address(user, address, True, True)
+
+
+def create_fake_collection():
+ collection = get_or_create_collection(name='%s collection' % fake.word())
+ for product in Product.objects.all().order_by('?')[:4]:
+ collection.products.add(product)
+ return collection
+
+
+def create_collections(how_many=2):
+ for dummy in range(how_many):
+ sale = create_fake_collection()
+ yield 'Collection: %s' % (sale,)