-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathcreate_data.py
More file actions
67 lines (51 loc) · 1.46 KB
/
create_data.py
File metadata and controls
67 lines (51 loc) · 1.46 KB
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
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projeto.settings")
django.setup()
import string
import timeit
from random import choice, randint, random
from projeto.produto.models import Produto
class Utils:
''' Métodos genéricos. '''
@staticmethod
def gen_digits(max_length):
return str(''.join(choice(string.digits) for i in range(max_length)))
class ProdutoClass:
@staticmethod
def criar_produtos(produtos):
Produto.objects.all().delete()
aux = []
for produto in produtos:
data = dict(
produto=produto,
importado=choice((True, False)),
ncm=Utils.gen_digits(8),
preco=random() * randint(10, 50),
estoque=randint(10, 200),
)
obj = Produto(**data)
aux.append(obj)
Produto.objects.bulk_create(aux)
produtos = (
'Apontador',
'Caderno 100 folhas',
'Caderno capa dura 200 folhas',
'Caneta esferográfica azul',
'Caneta esferográfica preta',
'Caneta esferográfica vermelha',
'Durex',
'Giz de cera 12 cores',
'Lapiseira 0.3 mm',
'Lapiseira 0.5 mm',
'Lapiseira 0.7 mm',
'Lápis de cor 24 cores',
'Lápis',
'Papel sulfite A4 pacote 100 folhas',
'Pasta elástica',
'Tesoura',
)
tic = timeit.default_timer()
ProdutoClass.criar_produtos(produtos)
toc = timeit.default_timer()
print('Tempo:', toc - tic)