· 9 years ago · Apr 09, 2016, 09:30 AM
1from shop.models import User
2from shop.models import ManufacturerCountry
3from shop.models import producer
4from shop.models import product
5from shop.models import category
6from shop.models import order
7from django.core.files import File
8from datetime import datetime
9import random
10
11def g_username():
12 s = ""
13 for i in range(random.randint(6, 18)):
14 s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890_-QWERTYUIOPASDFGHJKLZXCVBNM")
15 return s
16
17
18def g_email():
19 s = ""
20 for i in range(random.randint(13, 20)):
21 s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890")
22 s += random.choice(["@gmail.com", "@mail.ru", "@yandex.ru", "@yahoo.com"])
23 return s
24
25def g_password():
26 s = ""
27 for i in range(random.randint(20, 30)):
28 s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890 QWERTYUIOPASDFGHJKLZXCVBNM_-")
29 return s
30
31
32def g_name():
33 f = open('Random/names.txt')
34 names = f.readlines()
35 name = random.choice(names).strip()
36 f.close()
37 return name
38
39
40def g_surname():
41 f = open('Random/surnames.txt')
42 surnames = f.readlines()
43 surname = random.choice(names).strip()
44 f.close()
45 return name
46
47
48def g_ManufacturerCountry():
49 f = open('Random/countries.txt')
50 countries = f.readlines()
51 country = random.choice(countries).strip()
52 f.close()
53 return country
54
55def g_category():
56 f = open('Random/categories.txt')
57 categories = f.readlines()
58 category = random.choice(categories).strip()
59 f.close()
60 return category
61
62
63def g_producer():
64 f = open('Random/producers.txt')
65 producers = f.readlines()
66 producer = random.choice(producers).strip()
67 f.close()
68 return producer
69
70def g_price():
71 price = random.randint(1, 10000)
72 return price
73
74def g_product():
75 f = open('Random/products.txt')
76 products = f.readlines()
77 product = random.choice(countries).strip()
78 f.close()
79 return product(name = random.choice(products).strip(), price = g_price(), producer = g_producer(), manufacturerCountry = g_countyry())
80
81
82def g_order():
83 order_object = order()
84 order_object.save()
85 i = random.randint(1, 10)
86 order_object.products.add(i)
87 return order(customer = g_user())
88
89def g_products(n):
90 products = []
91 for i in range(n):
92 products.append(g_product())
93 product.objects.bulk_create(products)
94
95g_products(10)