Advertisement
Guest User

Untitled

a guest
Mar 25th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.53 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, city) VALUES
  12.            (%(first)s, %(middle)s)""""",
  13.             {'first': u'Точка продаж_' + str(x),
  14.             'middle': (random.randint(0, 1))})
  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, price, count) VALUES
  25.            (%(first)s, %(second)s, %(third)s)""""",
  26.             {'first': u'Блюдо_' + str(x),
  27.             'second': (random.randint(1, 100)),
  28.             'third': (random.randint(1, 10))})
  29.    
  30.  
  31. cur.execute(
  32.     """SELECT id from hd_customer;"""
  33. )
  34.  
  35. customers = cur.fetchall()
  36.  
  37. cur.execute(
  38.     """SELECT id from hd_dish;"""
  39. )
  40.  
  41. dishes = cur.fetchall()
  42.  
  43. cur.execute(
  44.     """SELECT id from hd_store;"""
  45. )
  46.  
  47. stores = cur.fetchall()
  48.  
  49. for x in range(40):
  50.     cur.execute(
  51.             """INSERT INTO hd_sales (name, customer, store, dish) VALUES
  52.            (%(name)s, %(customer)s, %(store)s), %(dish)s""""",
  53.             {'name': x,
  54.             'customer': customers.pop(),
  55.             'store': stores.pop()],
  56.             'dish': dishes.pop()})
  57.  
  58.  
  59.  
  60. conn.commit()
  61.  
  62. cur.close()
  63. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement