diff --git a/boards/migrations/0005_remove_thread_replies.py b/boards/migrations/0005_remove_thread_replies.py new file mode 100644 --- /dev/null +++ b/boards/migrations/0005_remove_thread_replies.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('boards', '0004_tag_required'), + ] + + operations = [ + migrations.RemoveField( + model_name='thread', + name='replies', + ), + ] diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -14,7 +14,6 @@ from boards import settings from boards.mdx_neboard import bbcode_extended from boards.models import PostImage from boards.models.base import Viewable -from boards.models.thread import Thread from boards.utils import datetime_to_epoch, cached_result @@ -111,7 +110,6 @@ class PostManager(models.Manager): post_image.id, post.id)) post.images.add(post_image) - thread.replies.add(post) list(map(thread.add_tag, tags)) if new_thread: @@ -134,7 +132,7 @@ class PostManager(models.Manager): for post in posts: post.delete() - def connect_replies(self, post): + def connect_replies(self, post): """ Connects replies to a post to show them as a reflink map """ @@ -295,7 +293,7 @@ class Post(models.Model, Viewable): return link - def get_thread(self) -> Thread: + def get_thread(self): """ Gets post's thread. """ diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -6,6 +6,7 @@ from django.db import models from boards import settings from boards.utils import cached_result +from boards.models.post import Post __author__ = 'neko259' @@ -52,8 +53,6 @@ class Thread(models.Model): tags = models.ManyToManyField('Tag') bump_time = models.DateTimeField() last_edit_time = models.DateTimeField() - replies = models.ManyToManyField('Post', symmetrical=False, null=True, - blank=True, related_name='tre+') archived = models.BooleanField(default=False) bumpable = models.BooleanField(default=True) @@ -78,10 +77,10 @@ class Thread(models.Model): logger.info('Bumped thread %d' % self.id) def get_reply_count(self): - return self.replies.count() + return self.get_replies().count() def get_images_count(self): - return self.replies.annotate(images_count=Count( + return self.get_replies().annotate(images_count=Count( 'images')).aggregate(Sum('images_count'))['images_count__sum'] def can_bump(self): @@ -121,7 +120,8 @@ class Thread(models.Model): Gets sorted thread posts """ - query = self.replies.order_by('pub_time').prefetch_related('images') + query = Post.objects.filter(thread_new=self) + query = query.order_by('pub_time').prefetch_related('images') if view_fields_only: query = query.defer('poster_user_agent') return query.all() @@ -146,7 +146,7 @@ class Thread(models.Model): Gets the first post of the thread """ - query = self.replies.order_by('pub_time') + query = self.get_replies().order_by('pub_time') if only_id: query = query.only('id') opening_post = query.first()