diff --git a/seeding/carts_faker.py b/seeding/carts_faker.py index 8568b081fd75ce9d785f7e2b9e9b240eb17e6808..bef31a22eb44165b2adbdf025e5cce12660c9b33 100644 --- a/seeding/carts_faker.py +++ b/seeding/carts_faker.py @@ -8,6 +8,7 @@ PRODUCTS_LIMIT = 200 # Get data from database select_users = '''SELECT id FROM users + WHERE category = \'user\' ORDER BY rand() LIMIT ''' + str(USERS_LIMIT) cursor.execute(select_users) @@ -31,9 +32,10 @@ for i in range(CARTS_COUNT): user_index = randint(0, USERS_LIMIT - 1) product_index = randint(0, PRODUCTS_LIMIT - 1) - while((users[user_index][0], products[product_index][0]) in existing_carts) : - user_id = randint(0, USERS_LIMIT - 1) - product_id = randint(0, PRODUCTS_LIMIT - 1) + while((users[user_index][0], products[product_index][0]) in existing_carts + or products[product_index][1] == 0) : + user_index = randint(0, USERS_LIMIT - 1) + product_index = randint(0, PRODUCTS_LIMIT - 1) user_id = users[user_index][0] product_id = products[product_index][0] @@ -42,6 +44,7 @@ for i in range(CARTS_COUNT): carts_val = (user_id, product_id, quantity) cursor.execute(carts_sql, carts_val) + existing_carts.append((user_id, product_id)) db.commit() print("Insertion success") \ No newline at end of file diff --git a/seeding/user_faker.py b/seeding/user_faker.py index ec69f4ec293e31affacaf324563b8a2f9a5d7763..718fbaebb30ddc08046c8d632313b1253edb7485 100644 --- a/seeding/user_faker.py +++ b/seeding/user_faker.py @@ -8,7 +8,7 @@ for i in range(USER_COUNT): name = faker.name() username = name + "-" + str(i) - email = name + "@gmail.com" + email = username + "@gmail.com" password = name description = faker.text() category = "user"