-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinsert_data.py
85 lines (73 loc) · 2.86 KB
/
insert_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
import django
import random
from faker import Faker
# Configurações do Django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ProjectOficina.settings') # Altere 'SeuProjeto' para o nome do seu projeto
django.setup()
from oficina.models import Services, Categories, Clients, Products, Payments, Orders, Employee
fake = Faker()
def insert_data():
# Inserir dados em Services
# for _ in range(15):
# service = Services(name=fake.word().capitalize(), price=round(random.uniform(10.0, 500.0), 2),
# description=fake.sentence())
# service.save()
# # Inserir dados em Categories
# for _ in range(10):
# category = Categories(name=fake.word().capitalize(), description=fake.sentence())
# category.save()
# Inserir dados em Clients
for _ in range(15):
client = Clients(
name=fake.name(),
email=fake.unique.email(),
addres=fake.address(),
cpf=fake.unique.random_int(min=10000000000, max=99999999999),
rg=fake.unique.random_int(min=100000000, max=999999999),
phone=fake.unique.phone_number()[:11] # Assegura que o telefone não exceda 11 caracteres
)
client.save()
# Inserir dados em Products
categories = Categories.objects.all() # Pegando todas as categorias
for _ in range(15):
product = Products(
name=fake.word().capitalize(),
status_p=random.choice(['1', '2']),
category=random.choice(categories),
description=fake.sentence()
)
product.save()
# Inserir dados em Payments
for _ in range(20):
payment = Payments(method=random.choice(['1', '2', '3', '4', '5'])) # Escolhendo aleatoriamente o método de pagamento
payment.save()
# Inserir dados em Orders
clients = Clients.objects.all()
products = Products.objects.all()
payments = Payments.objects.all()
services = Services.objects.all()
for _ in range(15):
order = Orders(
status_o=random.choice(['1', '2', '3', '4']),
o_client=random.choice(clients),
o_product=random.choice(products),
o_payment=random.choice(payments),
created_by=None,
s_price=random.choice(services)
)
order.save()
# Inserir dados em Employee
for _ in range(10):
employee = Employee(
e_name=fake.name(),
e_email=fake.unique.email(),
e_addres=fake.address(),
e_cpf=fake.unique.random_int(min=10000000000, max=99999999999),
e_rg=fake.unique.random_int(min=100000000, max=999999999),
e_phone=fake.unique.phone_number()[:11] # Assegura que o telefone não exceda 11 caracteres
)
employee.save()
print("Dados inseridos com sucesso!")
if __name__ == "__main__":
insert_data()