dr.botzo/dr_botzo/races/models.py

69 lines
1.6 KiB
Python

"""
races/models.py --- models for managing competitive races
"""
import logging
from django.db import models
from django.utils import timezone
log = logging.getLogger('dr_botzo.races')
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."""
race = models.ForeignKey(Race)
racer = models.ForeignKey(Racer)
update = models.TextField()
event_time = models.DateTimeField(default=timezone.now)
class Meta:
ordering = ['event_time',]
def __unicode__(self):
"""Text representation of a race update."""
local_time = timezone.localtime(self.event_time)
return u"{0:s} in {1:s} @ {2:s}".format(self.racer.nick, self.race.name,
local_time.strftime('%Y-%m-%d %H:%M:%S %Z'))
# vi:tabstop=4:expandtab:autoindent