From 749d8ab6bd44f7dedfd50a62c8ebef81d33d4f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulius=20=C5=A0ukys?= Date: Sat, 28 Jul 2018 09:42:49 +0200 Subject: [PATCH] Fix: on quote deletion - delete all quote's dangling tags --- smash/views.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/smash/views.py b/smash/views.py index cfc3b4d..998e0b0 100644 --- a/smash/views.py +++ b/smash/views.py @@ -131,6 +131,10 @@ def moderate(): elif request.form['submit'] == "Delete": quote = Quote.query.filter_by(id=request.form['quoteid']).first() + # Delete dangling tags (alive only with current Quote) + dangling_tags = [tag for tag in quote.tags if tag.quotes.count() == 1] + for tag in dangling_tags: + db.session.delete(tag) db.session.delete(quote) db.session.commit()