diff --git a/__pycache__/app.cpython-39.pyc b/__pycache__/app.cpython-39.pyc new file mode 100644 index 0000000..5b88ecf Binary files /dev/null and b/__pycache__/app.cpython-39.pyc differ diff --git a/app.py b/app.py index 47a3ec6..19199e2 100644 --- a/app.py +++ b/app.py @@ -104,19 +104,26 @@ def create(): # update category_name to refer to the newly added category category_name = new_category - if topic_tag == 'New topic' and new_topic: + # if topic_tag == 'New topic' and new_topic: + # conn.execute('INSERT INTO topics (content) VALUES (?)', + # (new_topic,)) + # conn.commit() + # topic_tag = new_topic + + # cat_id = conn.execute('SELECT id FROM categories WHERE category_name = (?);', + # (category_name,)).fetchone()['id'] + + # topic_id = conn.execute('SELECT id FROM topics WHERE content = (?);', + # (topic_tag,)).fetchone()['id'] + # conn.execute('INSERT INTO topic_cards (topic_id, card_id) VALUES (?,?)', + # (topic_id, cat_id)) + + if topic_tag =='New topic' and new_topic: conn.execute('INSERT INTO topics (content) VALUES (?)', - (new_topic,)) + (new_topic,)) conn.commit() topic_tag = new_topic - cat_id = conn.execute('SELECT id FROM categories WHERE category_name = (?);', - (category_name,)).fetchone()['id'] - - topic_id = conn.execute('SELECT id FROM topics WHERE content = (?);', - (topic_tag,)).fetchone()['id'] - conn.execute('INSERT INTO topic_cards (topic_id, card_id) VALUES (?,?)', - (topic_id, cat_id)) if not content: flash('plz write a content!') @@ -127,11 +134,14 @@ def create(): conn.execute('INSERT INTO cards (content, category_id) VALUES (?,?)', (content, cat_id)) + conn.commit() topic_id = conn.execute('SELECT id FROM topics WHERE content = (?);', (topic_tag,)).fetchone()['id'] + card_id = conn.execute('SELECT id FROM cards WHERE content = (?);', + (content,)).fetchone()['id'] conn.execute('INSERT INTO topic_cards (topic_id, card_id) VALUES (?,?)', - (topic_id, cat_id)) + (topic_id, card_id)) conn.commit() conn.close() diff --git a/diary_log.md b/diary_log.md index 420f764..cabf473 100644 --- a/diary_log.md +++ b/diary_log.md @@ -68,3 +68,10 @@ https://www.digitalocean.com/community/tutorials/how-to-use-many-to-many-databas ok, after a few tutorials I realized there are other ways of building this relational database with reading lists and notes and references, so I'm gonna move this log on a md file, and re do everything from scratch since it doesn't make sense as it is now. or maybe should I publish this log on the console log of the client? It is handier if the code is distributed in more files, with a dedicated schema.sql file and an init_db.py file where i can hadle the construction of the database this way of working reminds me of a tapestry, with threads being pulled from both the front and the back of the weaving frame + + + +03/12/22 + +Ok. I'm doing everything from scratch again +reason: the database design is not ok for what I wanna do D: \ No newline at end of file diff --git a/library.db b/library.db index 3062bf4..4ee6a6c 100644 Binary files a/library.db and b/library.db differ