comparison 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
comparison
equal deleted inserted replaced
238:a3b47d0f4df1 239:dcc929973bba
1 """ 1 """
2 This file contains the core Models used in gpp 2 This file contains the core Models used in gpp
3 """ 3 """
4 import datetime
5
4 from django.db import models 6 from django.db import models
5 from django.contrib import auth 7 from django.contrib.auth.models import User
6 8
7 9
8 class UserLastVisit(models.Model): 10 class UserLastVisit(models.Model):
9 """ 11 """
10 This model represents timestamps indicating a user's last visit to the 12 This model represents timestamps indicating a user's last visit to the
11 site. 13 site.
12 """ 14 """
13 user = models.ForeignKey(auth.models.User, unique=True) 15 user = models.ForeignKey(User, unique=True)
14 last_visit = models.DateTimeField(db_index=True) 16 last_visit = models.DateTimeField(db_index=True)
15 17
16 18
17 class AnonLastVisit(models.Model): 19 class AnonLastVisit(models.Model):
18 """ 20 """
20 users. 22 users.
21 """ 23 """
22 ip = models.CharField(max_length=16, db_index=True, unique=True) 24 ip = models.CharField(max_length=16, db_index=True, unique=True)
23 last_visit = models.DateTimeField(db_index=True) 25 last_visit = models.DateTimeField(db_index=True)
24 26
27
28 class Statistic(models.Model):
29 """
30 This model keeps track of site statistics. Currently, the only statistic
31 is the maximum number of users online. This stat is computed by a mgmt.
32 command that is run on a cron job to peek at the previous two models.
33 """
34 max_users = models.IntegerField()
35 max_users_date = models.DateTimeField()
36 max_anon_users = models.IntegerField()
37 max_anon_users_date = models.DateTimeField()
38
39 def __unicode__(self):
40 return u'%d users on %s' % (self.max_users,
41 self.max_users_date.strftime('%Y-%m-%d %H:%M:%S'))
42