2014-04-05 10:50:01 -05:00
|
|
|
"""
|
|
|
|
races/models.py --- models for managing competitive races
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2014-03-16 15:46:15 -05:00
|
|
|
from django.db import models
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
|
2014-04-05 10:50:01 -05:00
|
|
|
log = logging.getLogger('dr_botzo.races')
|
|
|
|
|
|
|
|
|
2014-03-16 15:46:15 -05:00
|
|
|
class Race(models.Model):
|
|
|
|
|
|
|
|
"""Track a race."""
|
|
|
|
|
|
|
|
key = models.CharField(max_length=16, primary_key=True)
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
description = models.TextField()
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
"""Text representation of a race."""
|
|
|
|
|
|
|
|
return u"{0:s} ({1:s})".format(self.name, self.key)
|
|
|
|
|
|
|
|
|
|
|
|
class Racer(models.Model):
|
|
|
|
|
|
|
|
"""Track a racer in a race."""
|
|
|
|
|
|
|
|
nick = models.CharField(max_length=64)
|
|
|
|
race = models.ForeignKey(Race)
|
|
|
|
|
|
|
|
joined = models.BooleanField(default=False)
|
|
|
|
started = models.BooleanField(default=False)
|
|
|
|
finished = models.BooleanField(default=False)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
unique_together = ('nick', 'race')
|
|
|
|
|
|
|
|
def __unicode__(self):
|
|
|
|
"""Text representation of a race racer."""
|
|
|
|
|
|
|
|
return u"{0:s} in {1:s}".format(self.nick, self.race.name)
|
|
|
|
|
|
|
|
|
|
|
|
class RaceUpdate(models.Model):
|
|
|
|
|
|
|
|
"""Periodic updates for a racer."""
|
|
|
|
|
2014-03-20 18:36:52 -05:00
|
|
|
race = models.ForeignKey(Race)
|
2014-03-16 15:46:15 -05:00
|
|
|
racer = models.ForeignKey(Racer)
|
|
|
|
update = models.TextField()
|
|
|
|
event_time = models.DateTimeField(default=timezone.now)
|
|
|
|
|
2014-04-05 17:24:31 -05:00
|
|
|
class Meta:
|
|
|
|
ordering = ['event_time',]
|
|
|
|
|
2014-03-16 15:46:15 -05:00
|
|
|
def __unicode__(self):
|
|
|
|
"""Text representation of a race update."""
|
|
|
|
|
|
|
|
local_time = timezone.localtime(self.event_time)
|
2014-03-20 18:36:52 -05:00
|
|
|
return u"{0:s} in {1:s} @ {2:s}".format(self.racer.nick, self.race.name,
|
2014-03-16 15:46:15 -05:00
|
|
|
local_time.strftime('%Y-%m-%d %H:%M:%S %Z'))
|
|
|
|
|
|
|
|
# vi:tabstop=4:expandtab:autoindent
|