Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. # coding=utf-8
  2. import psycopg2, random
  3. from django.utils import timezone
  4.  
  5. conn = psycopg2.connect("dbname=exam user=roman host=localhost password=123 port=5432")
  6.  
  7. cur = conn.cursor()
  8.  
  9. for x in range(50):
  10.     cur.execute(
  11.             """INSERT INTO hd_store (name, region) VALUES
  12.            (%(first)s, %(middle)s)""""",
  13.             {'first': u'Салон_' + str(x),
  14.             'middle': (random.randint(1, 100))})
  15.        
  16. for x in range(50):
  17.     cur.execute(
  18.             """INSERT INTO hd_customer (name) VALUES
  19.            (%(first)s)""""",
  20.             {'first': u'Заказчик_' + str(x),})
  21.    
  22. for x in range(50):
  23.     cur.execute(
  24.             """INSERT INTO hd_dish (name) VALUES
  25.            (%(first)s)""""",
  26.             {'first': u'Блюдо_' + str(x),})
  27.  
  28. cur.execute(
  29.     """SELECT id from hd_customer;"""
  30. )
  31.  
  32. customers = cur.fetchall()
  33.  
  34. cur.execute(
  35.     """SELECT id from hd_dish;"""
  36. )
  37.  
  38. dishes = cur.fetchall()
  39.  
  40. cur.execute(
  41.     """SELECT id from hd_store;"""
  42. )
  43.  
  44. stores = cur.fetchall()
  45.  
  46. for x in range(40):
  47.     cur.execute(
  48.             """INSERT INTO hd_sales (name, customer_id, dish_id, store_id) VALUES
  49.            (%(name)s, %(customer)s, %(dish)s, %(store)s)""""",
  50.             {'name': x,
  51.              'customer': customers.pop(),
  52.              'dish': dishes[random.randint(0, 1)],
  53.              'store': stores[random.randint(0, 1)]})
  54.  
  55.  
  56.  
  57. conn.commit()
  58.  
  59. cur.close()
  60. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement