diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -127,7 +127,7 @@ class Thread(models.Model): query = self.replies.order_by('pub_time').prefetch_related('images') if view_fields_only: - query = query.defer('poster_user_agent', 'text_markup_type') + query = query.defer('poster_user_agent') return query.all() def get_replies_with_images(self, view_fields_only=False): diff --git a/boards/tests/test_post.py b/boards/tests/test_post.py --- a/boards/tests/test_post.py +++ b/boards/tests/test_post.py @@ -112,4 +112,25 @@ class PostTests(TestCase): first_post = posts_in_second_page[0] self.assertEqual(all_threads[settings.THREADS_PER_PAGE].id, - first_post.id) \ No newline at end of file + first_post.id) + + def test_thread_replies(self): + """ + Tests that the replies can be queried from a thread in all possible + ways. + """ + + tag = Tag.objects.create(name='test_tag') + opening_post = Post.objects.create_post(title='title', text='text', + tags=[tag]) + thread = opening_post.get_thread() + + reply1 = Post.objects.create_post(title='title', text='text', thread=thread) + reply2 = Post.objects.create_post(title='title', text='text', thread=thread) + + replies = thread.get_replies() + self.assertTrue(len(replies) > 0, 'No replies found for thread.') + + replies = thread.get_replies(view_fields_only=True) + self.assertTrue(len(replies) > 0, + 'No replies found for thread with view fields only.')