diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -286,13 +286,12 @@ class Post(models.Model, Viewable): thread.save(update_fields=['last_edit_time']) @cached_result - def get_url(self, thread=None): + def get_url(self): """ Gets full url to the post. """ - if not thread: - thread = self.get_thread() + thread = self.get_thread() opening_id = thread.get_opening_post_id() @@ -445,6 +444,11 @@ class Post(models.Model, Viewable): return self.text def get_absolute_id(self) -> str: + """ + If the post has many threads, shows its main thread OP id in the post + ID. + """ + if self.get_threads().count() > 1: return '{}/{}'.format(self.get_thread().get_opening_post_id(), self.id) else: diff --git a/boards/models/thread.py b/boards/models/thread.py --- a/boards/models/thread.py +++ b/boards/models/thread.py @@ -121,7 +121,7 @@ class Thread(models.Model): """ query = Post.objects.filter(threads__in=[self]) - query = query.order_by('pub_time').prefetch_related('images') + query = query.order_by('pub_time').prefetch_related('images', 'thread', 'threads') if view_fields_only: query = query.defer('poster_user_agent') return query.all() diff --git a/boards/templates/boards/post.html b/boards/templates/boards/post.html --- a/boards/templates/boards/post.html +++ b/boards/templates/boards/post.html @@ -13,7 +13,7 @@ {% endif %}
- ({{ post.get_absolute_id }}) diff --git a/boards/templatetags/board.py b/boards/templatetags/board.py --- a/boards/templatetags/board.py +++ b/boards/templatetags/board.py @@ -25,18 +25,6 @@ def post_url(*args, **kwargs): return post.get_url() -@register.simple_tag(name='post_object_url') -def post_object_url(*args, **kwargs): - post = args[0] - - if 'thread' in kwargs: - post_thread = kwargs['thread'] - else: - post_thread = None - - return post.get_url(thread=post_thread) - - @register.simple_tag(name='image_actions') def image_actions(*args, **kwargs): image_link = args[0]