Add post count, image count, and unique posters to post detail
Just like 4chan has!!!!!!! Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -135,6 +135,18 @@ class Post(models.Model):
|
||||
self.__make_thumbnail()
|
||||
super(Post, self).save(*args, **kwargs)
|
||||
|
||||
def image_replies_count(self) -> int:
|
||||
"""
|
||||
Gets the number of image replies to this OP.
|
||||
"""
|
||||
# I would normally use the filter() and count() functions here, but
|
||||
# image__isnull=True does not seem to behave correctly. This is close
|
||||
# enough.
|
||||
return len([p for p in self.replies.all() if p.image])
|
||||
|
||||
def unique_posters(self) -> int:
|
||||
return len(set(p.ip for p in self.replies.all()))
|
||||
|
||||
def __make_thumbnail(self):
|
||||
image = Image.open(self.image)
|
||||
image.thumbnail(settings.THUMB_SIZE, Image.ANTIALIAS)
|
||||
|
||||
@@ -108,6 +108,10 @@ th {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.post_stats {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.post {
|
||||
background-color: var(--post-background);
|
||||
padding: 10px;
|
||||
|
||||
@@ -29,6 +29,15 @@
|
||||
</div>
|
||||
{# return links #}
|
||||
[ <a href="{% url 'board:board_detail' board.url %}">{% translate "Return" %}</a> ]
|
||||
{# posts / images / poster count / page #}
|
||||
<span class="post_stats">[
|
||||
<span title="{% translate 'Post replies' %}">{{post.replies.count}}</span>
|
||||
/
|
||||
<span title="{% translate 'Image replies' %}">{{post.image_replies_count}}</span>
|
||||
/
|
||||
<span title="{% translate 'Unique posters in this thread' %}">{{post.unique_posters}}</span>
|
||||
]
|
||||
</span>
|
||||
<hr />
|
||||
{# posts #}
|
||||
<div class="row post">
|
||||
|
||||
Reference in New Issue
Block a user