dr.botzo/dr.botzo/old-web/storycraft/models.py

65 lines
1.8 KiB
Python

from django.db import models
class StorycraftGame(models.Model):
id = models.IntegerField(primary_key=True)
round_mode = models.IntegerField()
game_length = models.IntegerField()
line_length = models.IntegerField()
random_method = models.IntegerField()
lines_per_turn = models.IntegerField()
status = models.CharField()
owner_nick = models.CharField()
owner_userhost = models.CharField()
start_time = models.DateTimeField()
end_time = models.DateTimeField()
class Meta:
db_table = 'storycraft_game'
ordering = ['id']
managed = False
def __unicode__(self):
"""Return a terse summary of the vital game info."""
return '#{0:d} - created on {1:s} by {2:s}, {3:s}'.format(self.id, self.start_time, self.owner_nick, self.status)
def is_completed(self):
"""Return if this game is completed."""
return self.status == 'COMPLETED' and self.end_time
class StorycraftPlayer(models.Model):
id = models.IntegerField(primary_key=True)
game = models.ForeignKey(StorycraftGame)
nick = models.CharField()
userhost = models.CharField()
class Meta:
db_table = 'storycraft_player'
ordering = ['id']
managed = False
def __unicode__(self):
"""Return the nick!user@host."""
return '{0:s}!{1:s}'.format(self.nick, self.userhost)
class StorycraftLine(models.Model):
id = models.IntegerField(primary_key=True)
game = models.ForeignKey(StorycraftGame)
player = models.ForeignKey(StorycraftPlayer)
line = models.TextField()
time = models.DateTimeField()
class Meta:
db_table = 'storycraft_line'
ordering = ['id']
managed = False
def __unicode__(self):
"""Just return the line."""
return '{0:s}'.format(self.line)
# vi:tabstop=4:expandtab:autoindent