-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdummmy_data.py
81 lines (56 loc) · 2.16 KB
/
dummmy_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
78
79
80
81
import os,django
os.environ['DJANGO_SETTINGS_MODULE'] = 'project.settings'
django.setup()
from faker import Faker
import random
from product.models import product as Product ,Brand,reviews
from django.contrib.auth.models import User
def seed_brand(n):
fake=Faker()
images=['apple.png','Download.jpeg','images_1.jpeg','images_2.jpeg','images_3.jpeg','images_4.jpeg','images_5.jpeg','images_6.jpeg','images_7.jpeg','images.jpeg','samsung.png']
for _ in range(n):
name = fake.name()
image=f"brand/{images[random.randint(0,10)]}"
Brand.objects.create(name=name,image=image)
print(f"seed{n} Brands ...")
def seed_product(n):
Flag_product=['Sale','Feature','New']
fake=Faker()
images=[ 'huawei.jpeg','Download_2.jpeg','Download.jpeg','3.jpeg','images.jpeg','4.jpeg','5.jpeg','6.jpeg','7.jpeg','8.jpeg','9.jpeg','10.jpeg','11.jpeg','12.jpeg','13.jpeg','14.jpeg','15.jpeg','16.jpeg','17.jpeg','18.jpeg','19.jpeg','20.jpeg','21.jpeg','22.jpeg']
for _ in range(n):
image=f"products/{images[random.randint(0,23)]}"
name=fake.name()
brand=Brand.objects.get(id=random.randint(504,528))
flag=Flag_product[random.randint(0,2)]
subtitle=fake.text(max_nb_chars=(500))
quantity=random.randint(2,30)
sku=random.randint(1,10000)
description=fake.text(max_nb_chars=(1000))
price=round(random.uniform(400.99,999.99),2)
Product.objects.create(
image=image,
name=name,
brand=brand,
flag=flag,
subtitle=subtitle,
quantity=quantity,
sku=sku,
description=description,
price=price
)
print(f"seed{n} products ...")
def seed_comment(n):
fake=Faker()
for _ in range(n) :
comment=fake.text(max_nb_chars=20)
rate=random.randint(1,6)
product=Product.objects.get(id=random.randint(3300,5000))
reviews.objects.create(
comment=comment,
rate=rate,
product=product
)
print(f"Seed{n} Comment ...")
seed_brand(20)
seed_product(1000)
seed_comment(300)