##// END OF EJS Templates
Delete replies properly when deleting a thread. Delete thread directly, not by...
neko259 -
r950:e663371b default
parent child Browse files
Show More
@@ -355,8 +355,7 b' class Post(models.Model, Viewable):'
355 355
356 356 def delete(self, using=None):
357 357 """
358 Deletes all post images and the post itself. If the post is opening,
359 thread with all posts is deleted.
358 Deletes all post images and the post itself.
360 359 """
361 360
362 361 for image in self.images.all():
@@ -364,12 +363,9 b' class Post(models.Model, Viewable):'
364 363 if image_refs_count == 1:
365 364 image.delete()
366 365
367 if self.is_opening():
368 self.get_thread().delete()
369 else:
370 thread = self.get_thread()
371 thread.last_edit_time = timezone.now()
372 thread.save()
366 thread = self.get_thread()
367 thread.last_edit_time = timezone.now()
368 thread.save()
373 369
374 370 super(Post, self).delete(using)
375 371
@@ -127,6 +127,10 b' class Thread(models.Model):'
127 127 return query.all()
128 128
129 129 def get_replies_with_images(self, view_fields_only=False):
130 """
131 Gets replies that have at least one image attached
132 """
133
130 134 return self.get_replies(view_fields_only).annotate(images_count=Count(
131 135 'images')).filter(images_count__gt=0)
132 136
@@ -173,10 +177,14 b' class Thread(models.Model):'
173 177 return self.get_opening_post().pub_time
174 178
175 179 def delete(self, using=None):
176 if self.replies.exists():
177 self.replies.all().delete()
180 """
181 Deletes thread with all replies.
182 """
183
184 for reply in self.replies.all():
185 reply.delete()
178 186
179 187 super(Thread, self).delete(using)
180 188
181 189 def __str__(self):
182 return 'T#{}/{}'.format(self.id, self.get_opening_post_id()) No newline at end of file
190 return 'T#{}/{}'.format(self.id, self.get_opening_post_id())
@@ -37,7 +37,7 b' class PostTests(TestCase):'
37 37 thread = opening_post.get_thread()
38 38 reply = Post.objects.create_post("", "", thread=thread)
39 39
40 opening_post.delete()
40 thread.delete()
41 41
42 42 self.assertFalse(Post.objects.filter(id=reply.id).exists(),
43 43 'Reply was not deleted with the thread.')
General Comments 0
You need to be logged in to leave comments. Login now