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:
2022-07-12 21:12:16 -07:00
parent 5df21ccb95
commit 3f1615f058
3 changed files with 25 additions and 0 deletions

View File

@@ -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)