Skip to content

Commit

Permalink
Added field total_read_time to Pageview, which is also populated at s…
Browse files Browse the repository at this point in the history
…ave().
  • Loading branch information
anttihirvonen committed May 6, 2012
1 parent 7906321 commit 51d0a56
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding field 'Pageview.total_read_time'
db.add_column('analytics_pageview', 'total_read_time',
self.gf('django.db.models.fields.IntegerField')(default=0),
keep_default=False)

def backwards(self, orm):
# Deleting field 'Pageview.total_read_time'
db.delete_column('analytics_pageview', 'total_read_time')

models = {
'analytics.pageview': {
'Meta': {'object_name': 'Pageview'},
'datetime': ('django.db.models.fields.DateTimeField', [], {}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'last_read_datetime': ('django.db.models.fields.DateTimeField', [], {}),
'referrer': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'screen_height': ('django.db.models.fields.IntegerField', [], {}),
'screen_width': ('django.db.models.fields.IntegerField', [], {}),
'service': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['analytics.Service']"}),
'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'total_read_time': ('django.db.models.fields.IntegerField', [], {}),
'url': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'user_id': ('django.db.models.fields.CharField', [], {'max_length': '8'})
},
'analytics.service': {
'Meta': {'object_name': 'Service'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'tracking_id': ('django.db.models.fields.CharField', [], {'max_length': '8'})
}
}

complete_apps = ['analytics']
10 changes: 10 additions & 0 deletions aaltoanalytics/apps/analytics/models.py
Expand Up @@ -32,6 +32,10 @@ class Pageview(models.Model):
datetime = models.DateTimeField()

last_read_datetime = models.DateTimeField()

# Read time in seconds, updated in save()
total_read_time = models.IntegerField()

# Needs a ton of new fields, like user/session id, os,
# any other browser parameter we are interested in..
screen_width = models.IntegerField(verbose_name="Leveys")
Expand All @@ -41,5 +45,11 @@ class Pageview(models.Model):
title = models.CharField(max_length=255)

referrer = models.CharField(max_length=255)

def save(self, *args, **kwargs):
difference = self.last_read_datetime - self.datetime
self.total_read_time = difference.seconds
super(Pageview, self).save(*args, **kwargs)


admin.site.register(Pageview)
3 changes: 2 additions & 1 deletion aaltoanalytics/settings/base.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
# Commong Django settings. This file contains
# settings that are common to different development and
# production environments. Use settings/local.py for all
Expand Down Expand Up @@ -38,7 +39,7 @@
USE_L10N = True

# If you set this to False, Django will not use timezone-aware datetimes.
USE_TZ = True
USE_TZ = False

LANGUAGES = (('fi', 'suomi'),)

Expand Down

0 comments on commit 51d0a56

Please sign in to comment.