aboutsummaryrefslogtreecommitdiffstats
path: root/timer/models.py
diff options
context:
space:
mode:
authorFilipp Lepalaan <f@0x00.co>2013-01-31 20:08:20 +0200
committerFilipp Lepalaan <f@0x00.co>2013-01-31 20:08:20 +0200
commitc0121b9b7f5041f6434a2e2dd24d3c68ed84b582 (patch)
treee3e8d0a05c45dabcc2a0399f902c6a59c92a9f4f /timer/models.py
parente613dc2b8b17e6f58a9666bee03578bb7ffc4067 (diff)
downloadopus-c0121b9b7f5041f6434a2e2dd24d3c68ed84b582.tar.gz
opus-c0121b9b7f5041f6434a2e2dd24d3c68ed84b582.tar.bz2
opus-c0121b9b7f5041f6434a2e2dd24d3c68ed84b582.zip
Initial commit
Diffstat (limited to 'timer/models.py')
-rw-r--r--timer/models.py44
1 files changed, 44 insertions, 0 deletions
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']