diff --git a/boards/models/post.py b/boards/models/post.py --- a/boards/models/post.py +++ b/boards/models/post.py @@ -12,9 +12,10 @@ from django.utils import timezone from markupfield.fields import MarkupField from neboard import settings -from boards import settings as boards_settings from boards import thumbs +POSTS_PER_DAY_RANGE = range(7) + BAN_REASON_AUTO = 'Auto' IMAGE_THUMB_SIZE = (200, 150) @@ -157,12 +158,19 @@ class PostManager(models.Manager): """Get count of posts for the current day""" today = datetime.now().date() - tomorrow = today + timedelta(1) - today_start = datetime.combine(today, dtime()) - today_end = datetime.combine(tomorrow, dtime()) - return self.filter(pub_time__lte=today_end, pub_time__gte=today_start)\ - .count() + posts_per_days = [] + for i in POSTS_PER_DAY_RANGE: + day_end = today + timedelta(i) + day_start = today + timedelta(i - 1) + day_time_start = datetime.combine(day_start, dtime()) + day_time_end = datetime.combine(day_end, dtime()) + + posts_per_days.append(float(self.filter(pub_time__lte=day_time_end, + pub_time__gte=day_time_start).count())) + + return sum(posts_per_day for posts_per_day in posts_per_days) / \ + len(posts_per_days) class Post(models.Model):