diff --git a/tutorial3/website/views.py b/tutorial3/website/views.py index 7e5afc0..b0cc844 100644 --- a/tutorial3/website/views.py +++ b/tutorial3/website/views.py @@ -39,7 +39,7 @@ def delete_post(id): if not post: flash("Post does not exist.", category='error') - elif current_user.id != post.id: + elif current_user.id != post.author: flash('You do not have permission to delete this post.', category='error') else: db.session.delete(post) diff --git a/tutorial4/website/views.py b/tutorial4/website/views.py index ba8185b..6416a35 100644 --- a/tutorial4/website/views.py +++ b/tutorial4/website/views.py @@ -39,9 +39,11 @@ def delete_post(id): if not post: flash("Post does not exist.", category='error') - elif current_user.id != post.id: + elif current_user.id != post.author: flash('You do not have permission to delete this post.', category='error') else: + for comment in post.comments: + db.session.delete(comment) db.session.delete(post) db.session.commit() flash('Post deleted.', category='success') diff --git a/tutorial5/website/views.py b/tutorial5/website/views.py index 511f7cc..fc5bd18 100644 --- a/tutorial5/website/views.py +++ b/tutorial5/website/views.py @@ -39,9 +39,11 @@ def delete_post(id): if not post: flash("Post does not exist.", category='error') - elif current_user.id != post.id: + elif current_user.id != post.author: flash('You do not have permission to delete this post.', category='error') else: + for comment in post.comments: + db.session.delete(comment) db.session.delete(post) db.session.commit() flash('Post deleted.', category='success')