# HG changeset patch # User neko259 # Date 2013-11-24 17:31:55 # Node ID f80d430659001eaa1c7065b340be04ee58a097ab # Parent 33667f743d7e767eb0bf885f2139387555e29a64 Get PPD for the last week 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):