-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathdummy_data.py
184 lines (152 loc) · 5.11 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
import os , django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'project.settings')
django.setup()
import random
from faker import Faker
from contact.models import Owner, Barber, Review, Category, Service, GalleryItem, Appointment, Message
from settings.models import Salon
from django.core.files import File
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand
from accounts.models import UserProfile, OwnerProfile, CustomUser
User = get_user_model()
fake = Faker()
def generate_users(n):
for _ in range(n):
username = fake.user_name()
email = fake.email()
password = '12345'
user = CustomUser.objects.create(
username=username,
email=email,
password=password
)
create_user_profile(user)
print(f'{n} users created successfully.')
def create_user_profile(user):
UserProfile.objects.create(
user=user,
profile_image=None,
barber=None,
)
def create_owner_profile(user, owner):
OwnerProfile.objects.create(
user=user,
image=f"barber_images/{random.randint(0,1)}",
owner=owner,
)
def generate_owners(n):
for _ in range(n):
owner = Owner.objects.create(
name=fake.name(),
logo=f"owner_logos/{random.randint(0,1)}",
email=fake.email(),
phone=fake.phone_number()[:15],
address=fake.address(),
website=fake.url(),
work_days=fake.time(),
about=fake.text(max_nb_chars=30),
)
# Create a CustomUser instance
user = CustomUser.objects.create(
username=fake.user_name(),
email=fake.email(),
password='12345'
)
# Create an OwnerProfile instance associated with the CustomUser and Owner
create_owner_profile(user, owner)
# Create Salon after Owner creation
Salon.objects.create(owner=owner)
print(f'Salon created successfully for Owner: {owner.name}')
print(f'{n} Owners were created successfully')
def generate_barbers(n):
fake = Faker()
image = ('person_1.jpg','person_2.jpg')
for _ in range(n):
barber = Barber.objects.create(
name=fake.name(),
image=f"barber_images/{random.randint(0,2)}",
expertise=fake.text(max_nb_chars=30),
experience_years=random.randint(1, 20),
)
print(f'{n} Barbers were created successfully')
def generate_reviews(n):
fake = Faker()
barbers = Barber.objects.all()
image = ('person_1.jpg','person_2.jpg')
for _ in range(n):
Review.objects.create(
image=f"review_images/{random.randint(0,2)}",
barber=random.choice(barbers),
customer_name=fake.name(),
email=fake.email(),
comment=fake.text(max_nb_chars=10),
rating=random.randint(1, 5),
)
print(f'{n} Reviews were created successfully')
def generate_categories(n):
fake = Faker()
for _ in range(n):
Category.objects.create(
name=fake.word(),
)
print(f'{n} Categories were created successfully')
def generate_services(n):
fake = Faker()
categories = Category.objects.all()
for _ in range(n):
Service.objects.create(
name=fake.word(),
category=random.choice(categories),
price=random.uniform(10.0, 100.0),
)
print(f'{n} Services were created successfully')
def generate_gallery_items(n):
fake = Faker()
categories = Category.objects.all()
services = Service.objects.all()
image = ('product_HSShU2u.webp','mask.jpeg')
for _ in range(n):
GalleryItem.objects.create(
name=fake.word(),
image=f"gallery_images/{random.randint(0,2)}",
description=fake.text(max_nb_chars=15),
category=random.choice(categories),
service=random.choice(services),
)
print(f'{n} GalleryItems were created successfully')
def generate_appointments(n):
fake = Faker()
barbers = Barber.objects.all()
services = Service.objects.all()
for _ in range(n):
Appointment.objects.create(
name=fake.name(),
barber=random.choice(barbers),
date=fake.date_this_month(),
time=fake.time(),
service_type=random.choice(services),
phone=fake.phone_number(),
email=fake.email(),
message=fake.text(max_nb_chars=15),
)
print(f'{n} Appointments were created successfully')
def generate_messages(n):
fake = Faker()
for _ in range(n):
Message.objects.create(
name=fake.name(),
email=fake.email(),
phone=fake.phone_number()[:15],
message=fake.text(max_nb_chars=15),
)
print(f'{n} Messages were created successfully')
# generate_owners(1)
# generate_users(1)
# generate_barbers(4)
# generate_reviews(4)
# generate_categories(4)
# generate_services(4)
# generate_gallery_items(4)
# generate_appointments(4)
generate_messages(4)