Skip to content
Snippets Groups Projects
Commit 99bc36df authored by fmk17's avatar fmk17
Browse files

Don't insert duplicate schedule

parent df78f4a1
No related branches found
No related tags found
No related merge requests found
......@@ -36,19 +36,32 @@ def get_schedules_for_user(user_id):
) for row in rows]
def insert_schedule(schedule):
connection.execute('''
INSERT INTO schedule
(time, day_week, location, meal, user_id, created_at)
VALUES
(?, ?, ?, ?, ?, ?)
cur = connection.execute('''
SELECT created_at
FROM schedule
WHERE time = ? and day_week = ? and location = ? and meal = ? and user_id = ?
''', (
schedule.time,
schedule.day_week,
schedule.location.name,
schedule.meal.name,
schedule.user_id,
schedule.created_at
schedule.user_id
))
row = cur.fetchone()
if not row:
connection.execute('''
INSERT INTO schedule
(time, day_week, location, meal, user_id, created_at)
VALUES
(?, ?, ?, ?, ?, ?)
''', (
schedule.time,
schedule.day_week,
schedule.location.name,
schedule.meal.name,
schedule.user_id,
schedule.created_at
))
def get_schedules_matching_time(time):
cur = connection.execute('''
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment