# HG changeset patch # User neko259 # Date 2015-08-18 12:19:51 # Node ID a8359cb2f308d2c9cca0798384f1e0bf71db0854 # Parent 87234f059e636152fc719ff1594b347eeb4385ab Delete attachments with posts diff --git a/boards/models/post/__init__.py b/boards/models/post/__init__.py --- a/boards/models/post/__init__.py +++ b/boards/models/post/__init__.py @@ -314,6 +314,11 @@ class Post(models.Model, Viewable): if image_refs_count == 1: image.delete() + for attachment in self.attachments.all(): + attachment_refs_count = Post.objects.filter(attachments__in=[attachment]).count() + if attachment_refs_count == 1: + attachment.delete() + thread = self.get_thread() thread.last_edit_time = timezone.now() thread.save()