-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdummy_data.py
82 lines (66 loc) · 2.56 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
import os ,django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
django.setup()
from faker import Faker
from products.models import Product, ProductImages, Brand, Review
import random
from django.utils.text import slugify
from django.contrib.auth.models import User
fake=Faker()
def seed_brands(num_brands):
imgs =['01.jpg','02.jpg','03.jpg','04.jpg','05.jpg','06.jpg', ]
for _ in range(num_brands):
brand = Brand.objects.create(
name=fake.company(),
image=f'brand/{imgs[random.randint(0,5)]}',
)
print('brand addec successfully')
def seed_product(n):
imgs =['01.jpg','02.jpg','03.jpg','04.jpg','05.jpg','06.jpg',
'07.jpg','08.jpg','09.jpg','10.jpg','11.jpg','12.jpg',
'13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg',
'19.jpg','20.jpg',
]
brand =Brand.objects.all()
for _ in range(n):
name = fake.company() # Generate a fake company name
Product.objects.create(
brand =brand[random.randint(0,len(brand)-1)] ,
name = name,
flag=fake.random_element(elements=('New', 'Sale', 'Feature')),
image = f'product/{imgs[random.randint(0,19)]}',
price = fake.random_number(digits=2),
sku=fake.unique.random_number(digits=5),
subtitle=fake.sentence(nb_words=60),
description=fake.paragraph(nb_sentences = 80),
quantity = random.randint(1, 100)
)
print('products added successfully')
def seed_review(n):
user = User.objects.all()
product = Product.objects.all()
for _ in range(n) :
Review.objects.create(
user = user[random.randint(0 ,len(user)-1)],
product =product[random.randint(0 ,len(product)-1)],
content = fake.sentence(nb_words =45),
rate = fake.random_element(elements = (i for i in range(1,6))),
)
print('added review successfully ')
def seed_product_img(n):
imgs =['01.jpg','02.jpg','03.jpg','04.jpg','05.jpg','06.jpg',
'07.jpg','08.jpg','09.jpg','10.jpg','11.jpg','12.jpg',
'13.jpg','14.jpg','15.jpg','16.jpg','17.jpg','18.jpg',
'19.jpg','20.jpg',
]
product = Product.objects.all()
for _ in range(n):
ProductImages.objects.create(
product =product[random.randint(0 ,len(product)-1)],
image = f'productimage/{imgs[random.randint(0,19)]}',
)
print('image added successfully ')
# seed_brands(200)
# seed_product(600)
seed_review(600)
seed_product_img(800)