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()