-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy-data.py
126 lines (69 loc) · 2.59 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
78
79
80
81
82
83
84
85
import os , django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
django.setup()
from faker import Faker
import random
from django.contrib.auth.models import User
from products.models import Product , Review , Brand , ProductImages
def add_brand(n):
fake = Faker()
images = ['1.jpg','2.jpg','3.jpg','4.jpeg','5.jpeg','6.png','7.png']
for _ in range(n):
Brand.objects.create(
name = fake.name() ,
image = f"brands/{images[random.randint(0,5)]}"
)
print(f"{n} Brands Was Added")
def add_products(n):
fake = Faker()
flags =["New","Sale","Feature"]
brands = Brand.objects.all()
images = ['1.jpg','2.png','3.jpeg','4.jpg','5.jpg','6.jpeg','7.jpeg','8.jpg','9.jpg','10.jpeg','11.jpeg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpeg','19.jpeg','20.jpeg']
for _ in range(n):
Product.objects.create(
name = fake.name() ,
image = f"products/{images[random.randint(0,5)]}",
price = round(random.uniform(20.99,99.99),2),
subtitle = fake.text(max_nb_chars = 350),
description = fake.text(max_nb_chars = 4000),
sku = random.randint(1000,1000000),
quantity = random.randint(5,100),
flag = random.choice(flags),
brand = random.choice(brands)
)
print(f"{n} Products Was Added")
def add_products_images(n):
products = Product.objects.all()
images = ['1.jpg','2.png','3.jpeg','4.jpg','5.jpg','6.jpeg','7.jpeg','8.jpg','9.jpg','10.jpeg','11.jpeg','12.jpg','13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpeg','19.jpeg','20.jpeg']
for _ in range(n):
ProductImages.objects.create(
image = f"products/{images[random.randint(0,18)]}",
product = random.choice(products)
)
print(f"{n} Products Images Was Added")
def add_users(n):
fake = Faker()
for _ in range(n):
User.objects.create(
username =fake.name() ,
email = fake.email(),
password = '123456'
)
print(f"{n} Users Was Added")
def add_review(n):
fake = Faker()
users = User.objects.all()
product = Product.objects.all()
for _ in range(n):
Review.objects.create(
user = random.choice(users) ,
product = random.choice(product) ,
review = fake.text(max_nb_chars = 100) ,
rate = random.randint(1,5)
)
print(f"{n} Reviews Was Added")
add_users(10)
add_brand(100)
add_products(50)
add_review(200)
add_products_images(200)