From c0121b9b7f5041f6434a2e2dd24d3c68ed84b582 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 31 Jan 2013 20:08:20 +0200 Subject: Initial commit --- timer/models.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 timer/models.py (limited to 'timer/models.py') diff --git a/timer/models.py b/timer/models.py new file mode 100644 index 0000000..1052eca --- /dev/null +++ b/timer/models.py @@ -0,0 +1,44 @@ +from datetime import datetime + +from django.db import models +from django.contrib.auth.models import User + +class Label(models.Model): + user = models.ForeignKey(User, editable=False) + title = models.CharField(max_length=128) + color = models.CharField(max_length=6, default="red") + + def get_absolute_url(self): + return "/timer/label/%d/events/" % self.pk + + def __unicode__(self): + return self.title + + class Meta: + ordering = ['-id'] + +class Event(models.Model): + user = models.ForeignKey(User, editable=False) + started_at = models.DateTimeField(default=datetime.now()) + duration = models.IntegerField(null=True, blank=True) + finished_at = models.DateTimeField(null=True, blank=True) # in seconds + labels = models.ManyToManyField(Label, null=True, blank=True) + notes = models.TextField(null=True, blank=True) + + def hours(self): + return self.duration/3600 + + def title(self): + if self.notes: + return '%s: %s' % (self.notes, self.duration()) + + return self.started_at + + def as_json(self): + return {'started_at': int(self.started_at.strftime('%s'))*1000} + + def get_absolute_url(self): + return "/timer/events/%d/" % self.pk + + class Meta: + ordering = ['-started_at'] -- cgit v1.2.3