Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding=utf-8
- import psycopg2, random
- from django.utils import timezone
- conn = psycopg2.connect("dbname=exam user=roman host=localhost password=123 port=5432")
- cur = conn.cursor()
- for x in range(50):
- cur.execute(
- """INSERT INTO hd_store (name, city) VALUES
- (%(first)s, %(middle)s)""""",
- {'first': u'Точка продаж_' + str(x),
- 'middle': (random.randint(0, 1))})
- for x in range(50):
- cur.execute(
- """INSERT INTO hd_customer (name) VALUES
- (%(first)s)""""",
- {'first': u'Заказчик_' + str(x),})
- for x in range(50):
- cur.execute(
- """INSERT INTO hd_dish (name, price, count) VALUES
- (%(first)s, %(second)s, %(third)s)""""",
- {'first': u'Блюдо_' + str(x),
- 'second': (random.randint(1, 100)),
- 'third': (random.randint(1, 10))})
- cur.execute(
- """SELECT id from hd_customer;"""
- )
- customers = cur.fetchall()
- cur.execute(
- """SELECT id from hd_dish;"""
- )
- dishes = cur.fetchall()
- cur.execute(
- """SELECT id from hd_store;"""
- )
- stores = cur.fetchall()
- for x in range(40):
- cur.execute(
- """INSERT INTO hd_sales (name, customer, store, dish) VALUES
- (%(name)s, %(customer)s, %(store)s), %(dish)s""""",
- {'name': x,
- 'customer': customers.pop(),
- 'store': stores.pop()],
- 'dish': dishes.pop()})
- conn.commit()
- cur.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement