-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_data.py
77 lines (56 loc) · 1.94 KB
/
dummy_data.py
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
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "project.settings")
import django
django.setup()
from products.models import Product, Category, Brand
import random
from faker import Faker
def seed_category(n):
fake = Faker()
images = ["1.png", "2.png", "3.png", "4.png", "5.png"]
for _ in range(n):
name = fake.name()
image = f"categorys/{images[random.randint(0,4)]}"
Category.objects.create(name=name, image=image)
print(f"successfully seeded {n} categorys")
def seed_brand(n):
fake = Faker()
images = ["1.png", "2.png", "3.png", "4.png", "5.png"]
for _ in range(n):
name = fake.name()
image = f"brands/{images[random.randint(0,4)]}"
Brand.objects.create(
name=name,
image=image,
category=Category.objects.get(id=random.randint(4, 13)),
)
print(f"successfully seeded {n} brands")
def seed_products(n):
fake = Faker()
images = ["1.png", "2.png", "3.png", "4.png", "5.png", "6.png", "7.png", "8.png"]
flag_type = ["New", "Feature", "Sale"]
for _ in range(n):
name = fake.name()
subtitle = fake.text(max_nb_chars=500)
sku = random.randint(1000, 100000)
description = fake.text(max_nb_chars=10000)
price = round(random.uniform(20.99, 99.99), 2)
image = f"products/{images[random.randint(0,7)]}"
flag = flag_type[random.randint(0, 2)]
quantity = random.randint(1, 100)
Product.objects.create(
name=name,
image=image,
subtitle=subtitle,
sku=sku,
desc=description,
price=price,
flag=flag,
quantity=quantity,
brand=Brand.objects.get(id=random.randint(4, 13)),
category=Category.objects.get(id=random.randint(4, 13)),
)
print(f"successfully seeded {n} products")
seed_brand(10)
seed_category(10)
seed_products(1000)