-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sample_data.py
More file actions
579 lines (542 loc) · 22 KB
/
Copy pathcreate_sample_data.py
File metadata and controls
579 lines (542 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
"""
Sree Fashions - Sample Data Creator
Run: python manage.py shell < create_sample_data.py
OR: python create_sample_data.py (from project root)
"""
import os
import django
import sys
# Setup Django
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sree_fashions.settings')
django.setup()
from django.utils import timezone
from datetime import timedelta
from decimal import Decimal
print("=" * 60)
print("Creating Sample Data for Sree Fashions...")
print("=" * 60)
# ============================================================
# SIZES
# ============================================================
from apps.products.models import Size, Color, Category, Product, ProductVariant
print("\n[SIZES]")
sizes_data = [
# Clothing
('XS', 'clothing', 1),
('S', 'clothing', 2),
('M', 'clothing', 3),
('L', 'clothing', 4),
('XL', 'clothing', 5),
('XXL', 'clothing', 6),
('3XL', 'clothing', 7),
# Kids
('2-3Y', 'kids', 1),
('3-4Y', 'kids', 2),
('4-5Y', 'kids', 3),
('5-6Y', 'kids', 4),
('6-7Y', 'kids', 5),
('7-8Y', 'kids', 6),
('8-9Y', 'kids', 7),
('9-10Y', 'kids', 8),
('10-11Y', 'kids', 9),
('11-12Y', 'kids', 10),
# Footwear
('6', 'footwear', 1),
('7', 'footwear', 2),
('8', 'footwear', 3),
('9', 'footwear', 4),
('10', 'footwear', 5),
('11', 'footwear', 6),
]
for name, size_type, order in sizes_data:
size, created = Size.objects.get_or_create(
name=name,
size_type=size_type,
defaults={'display_order': order}
)
if created:
print(f" Created size: {name} ({size_type})")
# ============================================================
# COLORS
# ============================================================
print("\n[COLORS]")
colors_data = [
('Black', '#000000', 1),
('White', '#FFFFFF', 2),
('Navy Blue', '#001F5B', 3),
('Royal Blue', '#4169E1', 4),
('Sky Blue', '#87CEEB', 5),
('Red', '#FF0000', 6),
('Maroon', '#800000', 7),
('Green', '#008000', 8),
('Olive Green', '#6B6B00', 9),
('Beige', '#F5F5DC', 10),
('Cream', '#FFFDD0', 11),
('Brown', '#A52A2A', 12),
('Grey', '#808080', 13),
('Light Grey', '#D3D3D3', 14),
('Pink', '#FFC0CB', 15),
('Hot Pink', '#FF69B4', 16),
('Purple', '#800080', 17),
('Yellow', '#FFFF00', 18),
('Orange', '#FFA500', 19),
('Mustard', '#FFDB58', 20),
('Teal', '#008080', 21),
('Mint Green', '#98FF98', 22),
('Coral', '#FF7F50', 23),
('Gold', '#FFD700', 24),
('Silver', '#C0C0C0', 25),
]
for name, hex_code, order in colors_data:
color, created = Color.objects.get_or_create(
name=name,
defaults={'hex_code': hex_code, 'display_order': order}
)
if created:
print(f" Created color: {name}")
# ============================================================
# CATEGORIES
# ============================================================
print("\n[CATEGORIES]")
categories_data = [
# Men's Main
{'name': "Men's Clothing", 'slug': 'mens-clothing', 'gender': 'men', 'parent': None, 'order': 1},
# Men's Sub
{'name': 'Men Shirts', 'slug': 'men-shirts', 'gender': 'men', 'parent': "Men's Clothing", 'order': 1},
{'name': 'Men T-Shirts', 'slug': 'men-tshirts', 'gender': 'men', 'parent': "Men's Clothing", 'order': 2},
{'name': 'Men Jeans', 'slug': 'men-jeans', 'gender': 'men', 'parent': "Men's Clothing", 'order': 3},
{'name': 'Men Trousers', 'slug': 'men-trousers', 'gender': 'men', 'parent': "Men's Clothing", 'order': 4},
{'name': 'Men Ethnic Wear', 'slug': 'men-ethnic', 'gender': 'men', 'parent': "Men's Clothing", 'order': 5},
{'name': 'Men Suits & Blazers', 'slug': 'men-suits', 'gender': 'men', 'parent': "Men's Clothing", 'order': 6},
# Women's Main
{'name': "Women's Clothing", 'slug': 'womens-clothing', 'gender': 'women', 'parent': None, 'order': 2},
# Women's Sub
{'name': 'Sarees', 'slug': 'sarees', 'gender': 'women', 'parent': "Women's Clothing", 'order': 1},
{'name': 'Salwar Suits', 'slug': 'salwar-suits', 'gender': 'women', 'parent': "Women's Clothing", 'order': 2},
{'name': 'Kurtis', 'slug': 'kurtis', 'gender': 'women', 'parent': "Women's Clothing", 'order': 3},
{'name': 'Women Dresses', 'slug': 'women-dresses', 'gender': 'women', 'parent': "Women's Clothing", 'order': 4},
{'name': 'Women Tops', 'slug': 'women-tops', 'gender': 'women', 'parent': "Women's Clothing", 'order': 5},
{'name': 'Lehengas', 'slug': 'lehengas', 'gender': 'women', 'parent': "Women's Clothing", 'order': 6},
# Kids Main
{'name': "Kids' Clothing", 'slug': 'kids-clothing', 'gender': 'kids', 'parent': None, 'order': 3},
# Kids Sub
{'name': 'Boys Shirts', 'slug': 'boys-shirts', 'gender': 'kids', 'parent': "Kids' Clothing", 'order': 1},
{'name': 'Boys Jeans', 'slug': 'boys-jeans', 'gender': 'kids', 'parent': "Kids' Clothing", 'order': 2},
{'name': 'Girls Frocks', 'slug': 'girls-frocks', 'gender': 'kids', 'parent': "Kids' Clothing", 'order': 3},
{'name': 'Kids Ethnic Wear', 'slug': 'kids-ethnic', 'gender': 'kids', 'parent': "Kids' Clothing", 'order': 4},
]
category_map = {}
# Create parent categories first
for cat_data in categories_data:
if cat_data['parent'] is None:
cat, created = Category.objects.get_or_create(
slug=cat_data['slug'],
defaults={
'name': cat_data['name'],
'gender': cat_data['gender'],
'is_active': True,
'is_featured': True,
'display_order': cat_data['order'],
}
)
category_map[cat_data['name']] = cat
if created:
print(f" Created category: {cat_data['name']}")
# Create child categories
for cat_data in categories_data:
if cat_data['parent'] is not None:
parent = category_map.get(cat_data['parent'])
cat, created = Category.objects.get_or_create(
slug=cat_data['slug'],
defaults={
'name': cat_data['name'],
'gender': cat_data['gender'],
'parent': parent,
'is_active': True,
'display_order': cat_data['order'],
}
)
category_map[cat_data['name']] = cat
if created:
print(f" Created sub-category: {cat_data['name']}")
# ============================================================
# PRODUCTS
# ============================================================
print("\n[PRODUCTS]")
products_data = [
# MEN'S PRODUCTS
{
'name': 'Premium Cotton Oxford Shirt',
'slug': 'premium-cotton-oxford-shirt',
'description': 'A classic Oxford shirt crafted from premium 100% cotton fabric. Perfect for formal and semi-formal occasions. Features a button-down collar, chest pocket, and a regular fit that provides all-day comfort.',
'short_description': 'Premium 100% cotton Oxford shirt for formal & semi-formal occasions',
'category': 'Men Shirts',
'gender': 'men',
'brand': 'StyleCraft',
'material': '100% Cotton',
'price': Decimal('1299.00'),
'discount_price': Decimal('899.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': True,
'sizes': ['S', 'M', 'L', 'XL', 'XXL'],
'colors': ['White', 'Sky Blue', 'Navy Blue'],
},
{
'name': 'Classic Slim Fit Jeans',
'slug': 'classic-slim-fit-jeans',
'description': 'These slim-fit jeans are made from premium denim fabric with just the right amount of stretch for comfort. Features a 5-pocket design and clean finish suitable for casual outings.',
'short_description': 'Premium slim-fit denim jeans with stretch comfort',
'category': 'Men Jeans',
'gender': 'men',
'brand': 'DenimKing',
'material': '98% Cotton, 2% Elastane',
'price': Decimal('1599.00'),
'discount_price': Decimal('1199.00'),
'is_featured': True,
'is_new_arrival': False,
'is_best_seller': True,
'sizes': ['30', 'M', 'L', 'XL'],
'colors': ['Navy Blue', 'Black', 'Light Grey'],
},
{
'name': 'Graphic Print Round Neck T-Shirt',
'slug': 'graphic-print-round-neck-tshirt',
'description': 'Stylish round neck t-shirt with trendy graphic print. Made from soft bio-washed cotton for superior comfort and vibrant color retention. Perfect for casual everyday wear.',
'short_description': 'Soft bio-washed cotton graphic t-shirt',
'category': 'Men T-Shirts',
'gender': 'men',
'brand': 'TrendWear',
'material': '100% Bio-washed Cotton',
'price': Decimal('599.00'),
'discount_price': Decimal('399.00'),
'is_featured': False,
'is_new_arrival': True,
'is_best_seller': False,
'is_flash_sale': True,
'sizes': ['S', 'M', 'L', 'XL', 'XXL'],
'colors': ['White', 'Black', 'Navy Blue', 'Red'],
},
{
'name': 'Traditional Kurta Pajama Set',
'slug': 'traditional-kurta-pajama-set',
'description': 'Elegant traditional kurta pajama set perfect for festive occasions and casual wear. Made from premium cotton fabric with intricate embroidery work. Includes kurta and matching pajama.',
'short_description': 'Elegant cotton kurta pajama set with embroidery',
'category': 'Men Ethnic Wear',
'gender': 'men',
'brand': 'EthnicPlus',
'material': 'Cotton Blend',
'price': Decimal('1999.00'),
'discount_price': Decimal('1499.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': False,
'sizes': ['S', 'M', 'L', 'XL', 'XXL'],
'colors': ['Cream', 'Beige', 'White'],
},
# WOMEN'S PRODUCTS
{
'name': 'Pure Silk Banarasi Saree',
'slug': 'pure-silk-banarasi-saree',
'description': 'Exquisite pure silk Banarasi saree with intricate zari work. Perfect for weddings and special occasions. Comes with a matching blouse piece. The rich texture and vibrant color make this saree a timeless piece.',
'short_description': 'Exquisite pure silk Banarasi saree with zari work',
'category': 'Sarees',
'gender': 'women',
'brand': 'SilkHaven',
'material': 'Pure Silk',
'price': Decimal('4999.00'),
'discount_price': Decimal('3499.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': True,
'sizes': ['Free Size'],
'colors': ['Red', 'Navy Blue', 'Green', 'Maroon'],
},
{
'name': 'Floral Print Anarkali Kurti',
'slug': 'floral-print-anarkali-kurti',
'description': 'Beautiful floral print Anarkali kurti made from breathable rayon fabric. Features a round neck, 3/4 sleeves, and an elegant flared silhouette. Perfect for casual and semi-formal occasions.',
'short_description': 'Breathable rayon floral Anarkali kurti',
'category': 'Kurtis',
'gender': 'women',
'brand': 'EthnicCharm',
'material': 'Rayon',
'price': Decimal('899.00'),
'discount_price': Decimal('649.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': True,
'is_flash_sale': True,
'sizes': ['XS', 'S', 'M', 'L', 'XL', 'XXL'],
'colors': ['Pink', 'Coral', 'Mint Green', 'Yellow'],
},
{
'name': 'Designer Salwar Suit Set',
'slug': 'designer-salwar-suit-set',
'description': 'Stunning designer salwar suit set in premium cotton fabric. Features beautiful embroidery on the kurta and comes with matching salwar and dupatta. Perfect for festivals and celebrations.',
'short_description': 'Premium cotton salwar suit with embroidery and dupatta',
'category': 'Salwar Suits',
'gender': 'women',
'brand': 'FestiveLine',
'material': 'Cotton Silk',
'price': Decimal('2499.00'),
'discount_price': Decimal('1799.00'),
'is_featured': False,
'is_new_arrival': True,
'is_best_seller': False,
'sizes': ['S', 'M', 'L', 'XL', 'XXL'],
'colors': ['Purple', 'Teal', 'Mustard', 'Maroon'],
},
{
'name': 'Western Wrap Dress',
'slug': 'western-wrap-dress',
'description': 'Chic western wrap dress perfect for brunches, parties, and casual outings. Made from high-quality crepe fabric that drapes beautifully. Features a V-neck and tie waist for a flattering silhouette.',
'short_description': 'Chic crepe wrap dress with V-neck and tie waist',
'category': 'Women Dresses',
'gender': 'women',
'brand': 'ModernElle',
'material': 'Crepe',
'price': Decimal('1299.00'),
'discount_price': Decimal('899.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': False,
'sizes': ['XS', 'S', 'M', 'L', 'XL'],
'colors': ['Black', 'Navy Blue', 'Floral Print'],
},
# KIDS' PRODUCTS
{
'name': "Kids' Cotton T-Shirt 3-Pack",
'slug': 'kids-cotton-tshirt-3pack',
'description': 'Super soft 100% cotton t-shirts for kids. Pack of 3 with fun prints and vibrant colors. Machine washable and designed for active kids. Available in various sizes for age groups 2-12 years.',
'short_description': 'Super soft cotton t-shirts pack of 3 for kids 2-12 years',
'category': 'Boys Shirts',
'gender': 'kids',
'brand': 'KidsComfort',
'material': '100% Cotton',
'price': Decimal('799.00'),
'discount_price': Decimal('599.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': True,
'sizes': ['2-3Y', '3-4Y', '4-5Y', '5-6Y', '6-7Y', '7-8Y'],
'colors': ['Red', 'Blue', 'Yellow', 'Green'],
},
{
'name': "Girls' Princess Frock",
'slug': 'girls-princess-frock',
'description': 'Adorable princess-style frock for girls. Made from soft net and satin fabric with beautiful lace detailing. Perfect for parties, birthdays, and special occasions. Easy to wear with side zipper.',
'short_description': 'Adorable net and satin princess frock for girls',
'category': 'Girls Frocks',
'gender': 'kids',
'brand': 'LittlePrincess',
'material': 'Net & Satin',
'price': Decimal('999.00'),
'discount_price': Decimal('749.00'),
'is_featured': True,
'is_new_arrival': True,
'is_best_seller': False,
'sizes': ['2-3Y', '3-4Y', '4-5Y', '5-6Y', '6-7Y'],
'colors': ['Pink', 'Purple', 'White', 'Yellow'],
},
{
'name': "Kids' Ethnic Sherwani Set",
'slug': 'kids-ethnic-sherwani-set',
'description': 'Gorgeous ethnic sherwani set for kids. Perfect for weddings, festivals, and celebrations. Comes with kurta, pajama, and waistcoat. Made from premium fabric with beautiful embroidery.',
'short_description': 'Premium ethnic sherwani set for kids celebrations',
'category': 'Kids Ethnic Wear',
'gender': 'kids',
'brand': 'EthnicKids',
'material': 'Cotton Blend with Embroidery',
'price': Decimal('1499.00'),
'discount_price': Decimal('1099.00'),
'is_featured': False,
'is_new_arrival': True,
'is_best_seller': True,
'sizes': ['2-3Y', '3-4Y', '4-5Y', '5-6Y', '6-7Y', '7-8Y', '8-9Y'],
'colors': ['Cream', 'Gold', 'Maroon'],
},
]
# Get sizes and colors
size_objects = {s.name: s for s in Size.objects.all()}
color_objects = {c.name: c for c in Color.objects.all()}
for i, prod_data in enumerate(products_data, 1):
product, created = Product.objects.get_or_create(
slug=prod_data['slug'],
defaults={
'name': prod_data['name'],
'description': prod_data['description'],
'short_description': prod_data.get('short_description', ''),
'category': category_map.get(prod_data['category']),
'gender': prod_data['gender'],
'brand': prod_data.get('brand', ''),
'material': prod_data.get('material', ''),
'price': prod_data['price'],
'discount_price': prod_data.get('discount_price'),
'is_active': True,
'is_featured': prod_data.get('is_featured', False),
'is_new_arrival': prod_data.get('is_new_arrival', False),
'is_best_seller': prod_data.get('is_best_seller', False),
'is_flash_sale': prod_data.get('is_flash_sale', False),
'flash_sale_end': (
timezone.now() + timedelta(days=3)
if prod_data.get('is_flash_sale') else None
),
}
)
if created:
print(f" Created product {i}: {prod_data['name']}")
# Create variants
variant_count = 0
for size_name in prod_data.get('sizes', ['M']):
size_obj = size_objects.get(size_name)
if not size_obj:
# Create size if not exists
size_obj, _ = Size.objects.get_or_create(
name=size_name,
defaults={'size_type': 'clothing', 'display_order': 99}
)
for j, color_name in enumerate(prod_data.get('colors', ['Black'])):
color_obj = color_objects.get(color_name)
if not color_obj:
continue
import random
sku = f"SF-{prod_data['slug'][:8].upper()}-{size_name}-{color_name[:3].upper()}-{random.randint(100, 999)}"
stock = random.randint(5, 50)
try:
variant, v_created = ProductVariant.objects.get_or_create(
product=product,
size=size_obj,
color=color_obj,
defaults={
'sku': sku,
'stock': stock,
'additional_price': Decimal('0.00'),
'is_active': True,
}
)
if v_created:
variant_count += 1
except Exception:
pass
print(f" → Created {variant_count} variants")
else:
print(f" Product already exists: {prod_data['name']}")
# ============================================================
# COUPONS
# ============================================================
print("\n[COUPONS]")
from apps.coupons.models import Coupon
coupons_data = [
{
'code': 'WELCOME10',
'description': '10% off on first order',
'discount_type': 'percentage',
'discount_value': Decimal('10.00'),
'min_order_value': Decimal('500.00'),
'max_discount_amount': Decimal('200.00'),
'max_uses': 1000,
},
{
'code': 'FLAT100',
'description': 'Flat ₹100 off on orders above ₹999',
'discount_type': 'fixed',
'discount_value': Decimal('100.00'),
'min_order_value': Decimal('999.00'),
'max_uses': 500,
},
{
'code': 'SALE20',
'description': '20% off on all products',
'discount_type': 'percentage',
'discount_value': Decimal('20.00'),
'min_order_value': Decimal('1000.00'),
'max_discount_amount': Decimal('500.00'),
'max_uses': 200,
},
{
'code': 'FREESHIP',
'description': 'Free shipping on all orders',
'discount_type': 'free_shipping',
'discount_value': Decimal('0.00'),
'min_order_value': Decimal('0.00'),
'max_uses': 100,
},
]
now = timezone.now()
for coupon_data in coupons_data:
coupon, created = Coupon.objects.get_or_create(
code=coupon_data['code'],
defaults={
**coupon_data,
'valid_from': now,
'valid_to': now + timedelta(days=365),
'is_active': True,
'used_count': 0,
'max_uses_per_user': 1,
}
)
if created:
print(f" Created coupon: {coupon_data['code']}")
else:
print(f" Coupon exists: {coupon_data['code']}")
# ============================================================
# BANNERS
# ============================================================
print("\n[BANNERS]")
from apps.core.models import Banner
banners_data = [
{
'title': 'New Season Collection',
'subtitle': 'Men\'s Fashion',
'description': 'Discover the latest trends in men\'s fashion',
'button_text': 'Shop Men',
'button_link': '/shop/?gender=men',
'banner_type': 'hero',
'display_order': 1,
},
{
'title': 'Women\'s Collection 2024',
'subtitle': 'Elegance Redefined',
'description': 'From sarees to western wear, find your style',
'button_text': 'Shop Women',
'button_link': '/shop/?gender=women',
'banner_type': 'hero',
'display_order': 2,
},
{
'title': 'Kids\' Fun Fashion',
'subtitle': 'Cute & Comfortable',
'description': 'Adorable outfits for your little ones',
'button_text': 'Shop Kids',
'button_link': '/shop/?gender=kids',
'banner_type': 'hero',
'display_order': 3,
},
]
for banner_data in banners_data:
banner, created = Banner.objects.get_or_create(
title=banner_data['title'],
defaults={
**banner_data,
'image': 'banners/placeholder.jpg',
'is_active': True,
}
)
if created:
print(f" Created banner: {banner_data['title']}")
print("\n" + "=" * 60)
print("✅ Sample data created successfully!")
print("=" * 60)
print(f"\n📊 Summary:")
print(f" Sizes: {Size.objects.count()}")
print(f" Colors: {Color.objects.count()}")
print(f" Categories: {Category.objects.count()}")
print(f" Products: {Product.objects.count()}")
print(f" Variants: {ProductVariant.objects.count()}")
print(f" Coupons: {Coupon.objects.count()}")
print(f" Banners: {Banner.objects.count()}")
print("\n🚀 Visit http://127.0.0.1:8000 to see the store!")
print("🔐 Admin: http://127.0.0.1:8000/admin-panel/")
print("📦 Django Admin: http://127.0.0.1:8000/admin/")