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, region) VALUES
- (%(first)s, %(middle)s)""""",
- {'first': u'Салон_' + str(x),
- 'middle': (random.randint(1, 100))})
- 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) VALUES
- (%(first)s)""""",
- {'first': u'Блюдо_' + str(x),})
- 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_id, dish_id, store_id) VALUES
- (%(name)s, %(customer)s, %(dish)s, %(store)s)""""",
- {'name': x,
- 'customer': customers.pop(),
- 'dish': dishes[random.randint(0, 1)],
- 'store': stores[random.randint(0, 1)]})
- conn.commit()
- cur.close()
- conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement