diff gpp/core/models.py @ 239:dcc929973bba

Fix the max users online statistic as per ticket #90.
author Brian Neal <bgneal@gmail.com>
date Sun, 12 Sep 2010 18:30:23 +0000
parents 423c39ee44e0
children 3fe60148f75c
line wrap: on
line diff
--- a/gpp/core/models.py	Sun Sep 12 04:04:42 2010 +0000
+++ b/gpp/core/models.py	Sun Sep 12 18:30:23 2010 +0000
@@ -1,8 +1,10 @@
 """
 This file contains the core Models used in gpp
 """
+import datetime
+
 from django.db import models
-from django.contrib import auth
+from django.contrib.auth.models import User
 
 
 class UserLastVisit(models.Model):
@@ -10,7 +12,7 @@
     This model represents timestamps indicating a user's last visit to the
     site.
     """
-    user = models.ForeignKey(auth.models.User, unique=True)
+    user = models.ForeignKey(User, unique=True)
     last_visit = models.DateTimeField(db_index=True)
 
 
@@ -22,3 +24,19 @@
     ip = models.CharField(max_length=16, db_index=True, unique=True)
     last_visit = models.DateTimeField(db_index=True)
 
+
+class Statistic(models.Model):
+    """
+    This model keeps track of site statistics. Currently, the only statistic
+    is the maximum number of users online. This stat is computed by a mgmt.
+    command that is run on a cron job to peek at the previous two models.
+    """
+    max_users = models.IntegerField()
+    max_users_date = models.DateTimeField()
+    max_anon_users = models.IntegerField()
+    max_anon_users_date = models.DateTimeField()
+
+    def __unicode__(self):
+        return u'%d users on %s' % (self.max_users, 
+                self.max_users_date.strftime('%Y-%m-%d %H:%M:%S'))
+