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)
|
||||
|
||||
Reference in New Issue
Block a user