Advertisement
Guest User

Untitled

a guest
Apr 9th, 2016
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.42 KB | None | 0 0
  1. from shop.models import User
  2. from shop.models import ManufacturerCountry
  3. from shop.models import producer
  4. from shop.models import product
  5. from shop.models import category
  6. from shop.models import order
  7. from django.core.files import File
  8. from datetime import datetime
  9. import random
  10.  
  11. def g_username():
  12.     s = ""
  13.     for i in range(random.randint(6, 18)):
  14.         s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890_-QWERTYUIOPASDFGHJKLZXCVBNM")
  15.     return s
  16.  
  17.  
  18. def 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.  
  25. def g_password():
  26.     s = ""
  27.     for i in range(random.randint(20, 30)):
  28.         s += random.choice("qwertyuiopasdfghjklzcvbxnm1234567890 QWERTYUIOPASDFGHJKLZXCVBNM_-")
  29.     return s
  30.  
  31.  
  32. def 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.  
  40. def 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.  
  48. def 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.  
  55. def 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.  
  63. def 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.  
  70. def g_price():
  71.     price = random.randint(1, 10000)
  72.     return price
  73.  
  74. def 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.  
  82. def 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.  
  89. def g_products(n):
  90.     products = []
  91.     for i in range(n):
  92.         products.append(g_product())
  93.     product.objects.bulk_create(products)
  94.  
  95. g_products(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement