Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from shop.models import User
- from shop.models import ManufacturerCountry
- from shop.models import producer
- from shop.models import product
- from shop.models import category
- from shop.models import order
- from django.core.files import File
- from datetime import datetime
- import random
- def g_username():
- s = ""
- for i in range(random.randint(6, 18)):
- s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890_-QWERTYUIOPASDFGHJKLZXCVBNM")
- return s
- def g_email():
- s = ""
- for i in range(random.randint(13, 20)):
- s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890")
- s += random.choice(["@gmail.com", "@mail.ru", "@yandex.ru", "@yahoo.com"])
- return s
- def g_password():
- s = ""
- for i in range(random.randint(20, 30)):
- s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890 QWERTYUIOPASDFGHJKLZXCVBNM_-")
- return s
- def g_name():
- f = open('Random/names.txt')
- names = f.readlines()
- name = random.choice(names).strip()
- f.close()
- return name
- def g_user():
- return User(username = g_username(), first_name = g_name(), last_name = g_surname(), email = g_email(), password = g_password())
- def g_surname():
- f = open('Random/surnames.txt')
- surnames = f.readlines()
- surname = random.choice(surnames).strip()
- f.close()
- return surname
- def g_ManufacturerCountry():
- f = open('Random/countries.txt')
- countries = f.readlines()
- f.close()
- return ManufacturerCountry(name = random.choice(countries).strip())
- def g_category():
- f = open('Random/categories.txt')
- categories = f.readlines()
- f.close()
- return category(name = random.choice(categories).strip())
- def g_producer():
- f = open('Random/producers.txt')
- producers = f.readlines()
- f.close()
- return producer(name = random.choice(producers).strip())
- def g_price():
- price = random.randint(1, 10000)
- return price
- def g_product():
- f = open('Random/products.txt')
- products = f.readlines()
- f.close()
- return product(name = random.choice(products).strip(), price = g_price(), producer = g_producer(), manufacturerCountry = g_ManufacturerCountry())
- def get_user():
- users = User.objects.all()[:]
- return random.choice(users)
- def g_order():
- #order1 = order(user = get_user)
- #order1.save()
- #i = random.randint(1, 10)
- #order1.products.add(i)
- return order(user = get_user())
- def g_products(n):
- products = []
- for i in range(n):
- products.append(g_product())
- product.objects.bulk_create(products)
- def g_categories(n=10):
- categories = []
- for i in range(n):
- categories.append(g_category())
- category.objects.bulk_create(categories)
- def g_users(n=10):
- users = []
- for i in range(n):
- users.append(g_user())
- User.objects.bulk_create(users)
- def g_orders(n=10):
- orders = []
- for i in range(n):
- orders.append(g_order())
- order.objects.bulk_create(orders)
- add_products(n=n)
- def add_products(n=10):
- i = 1
- while i < n+1:
- orderr = order.objects.get(id= i)
- #amount_of_products = product.objects.all().count()
- #j = random.randint(1, amount_of_products)
- #orderr.products.add(j)
- amount_of_products = product.objects.all().count()
- j = 1
- while j < random.randint(1, amount_of_products):
- j = random.randint(1, amount_of_products)
- orderr.products.add(j)
- j = j+1
- i = i+1
- print orderr
- #order1 = order(user = get_user)
- #order1.save()
- #i = random.randint(1, 10)
- #order1.products.add(i)
- #g_users(n=10)
- #g_products(n=10)
- #g_orders(n=10)
- #add_products(n=10)
- #User.objects.all()
- order.objects.all()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement