Show More
@@ -355,8 +355,7 b' class Post(models.Model, Viewable):' | |||||
355 |
|
355 | |||
356 | def delete(self, using=None): |
|
356 | def delete(self, using=None): | |
357 | """ |
|
357 | """ | |
358 |
Deletes all post images and the post itself. |
|
358 | Deletes all post images and the post itself. | |
359 | thread with all posts is deleted. |
|
|||
360 | """ |
|
359 | """ | |
361 |
|
360 | |||
362 | for image in self.images.all(): |
|
361 | for image in self.images.all(): | |
@@ -364,12 +363,9 b' class Post(models.Model, Viewable):' | |||||
364 | if image_refs_count == 1: |
|
363 | if image_refs_count == 1: | |
365 | image.delete() |
|
364 | image.delete() | |
366 |
|
365 | |||
367 | if self.is_opening(): |
|
366 | thread = self.get_thread() | |
368 | self.get_thread().delete() |
|
367 | thread.last_edit_time = timezone.now() | |
369 |
|
|
368 | thread.save() | |
370 | thread = self.get_thread() |
|
|||
371 | thread.last_edit_time = timezone.now() |
|
|||
372 | thread.save() |
|
|||
373 |
|
369 | |||
374 | super(Post, self).delete(using) |
|
370 | super(Post, self).delete(using) | |
375 |
|
371 |
@@ -127,6 +127,10 b' class Thread(models.Model):' | |||||
127 | return query.all() |
|
127 | return query.all() | |
128 |
|
128 | |||
129 | def get_replies_with_images(self, view_fields_only=False): |
|
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 | return self.get_replies(view_fields_only).annotate(images_count=Count( |
|
134 | return self.get_replies(view_fields_only).annotate(images_count=Count( | |
131 | 'images')).filter(images_count__gt=0) |
|
135 | 'images')).filter(images_count__gt=0) | |
132 |
|
136 | |||
@@ -173,10 +177,14 b' class Thread(models.Model):' | |||||
173 | return self.get_opening_post().pub_time |
|
177 | return self.get_opening_post().pub_time | |
174 |
|
178 | |||
175 | def delete(self, using=None): |
|
179 | def delete(self, using=None): | |
176 | if self.replies.exists(): |
|
180 | """ | |
177 | self.replies.all().delete() |
|
181 | Deletes thread with all replies. | |
|
182 | """ | |||
|
183 | ||||
|
184 | for reply in self.replies.all(): | |||
|
185 | reply.delete() | |||
178 |
|
186 | |||
179 | super(Thread, self).delete(using) |
|
187 | super(Thread, self).delete(using) | |
180 |
|
188 | |||
181 | def __str__(self): |
|
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 | thread = opening_post.get_thread() |
|
37 | thread = opening_post.get_thread() | |
38 | reply = Post.objects.create_post("", "", thread=thread) |
|
38 | reply = Post.objects.create_post("", "", thread=thread) | |
39 |
|
39 | |||
40 |
|
|
40 | thread.delete() | |
41 |
|
41 | |||
42 | self.assertFalse(Post.objects.filter(id=reply.id).exists(), |
|
42 | self.assertFalse(Post.objects.filter(id=reply.id).exists(), | |
43 | 'Reply was not deleted with the thread.') |
|
43 | 'Reply was not deleted with the thread.') |
General Comments 0
You need to be logged in to leave comments.
Login now