forked from rafah91/BookStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_data.py
54 lines (41 loc) · 1.43 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
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 books.models import Author , Book , Review
def add_authors(n):
fake = Faker()
for x in range(n):
Author.objects.create(
name = fake.name() ,
birth_date=fake.date() ,
biography=fake.text(max_nb_chars=1000) ,
)
print(f'{n} authors was created successfully')
def add_books(n):
fake = Faker()
images = ['1.jpg','2.jpg','3.jpg','4.jpg','5.jpg','6.jpg','7.jpg']
for x in range(n):
Book.objects.create(
title = fake.text(max_nb_chars = 10) ,
publication_date= fake.date() ,
image= f"bookimages/{images[random.randint(0,6)]}",
price= round(random.uniform(19.99,99.99),2) ,
author = Author.objects.get(id=random.randint(1,50)),
)
print(f'{n} books was created successfully')
def add_reviews(n):
fake = Faker()
for x in range(n):
Review.objects.create(
viewer_name = User.objects.get(id=random.randint(1,5)),
book = Book.objects.get(id=random.randint(1,1029)) ,
rating = random.randint(1,5) ,
content = fake.text(max_nb_chars=200)
)
print(f'{n} Reviews was created successfully')
#add_authors()
#add_books(18)
#add_reviews(3000)