Titivillus/quest/models.py

144 lines
3.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
"""
The main quest models.
"""
2018-08-10 08:39:51 -04:00
from django.db import models
from django.conf import settings
2018-08-23 11:57:37 -04:00
from django.core.validators import MaxValueValidator, MinValueValidator
2018-08-10 08:39:51 -04:00
class Quest(models.Model):
"""
The meta quest object. Contains general information about the quest.
"""
title = models.CharField(max_length=200)
owner = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE)
2018-09-21 14:18:54 -04:00
anon_name = models.CharField(max_length=20, default="Anonymous")
2018-08-24 21:51:03 -04:00
class Message(models.Model):
"""
Represents a chat message.
"""
quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
blank=True,
null=True)
timestamp = models.DateTimeField(auto_now=True)
message = models.TextField(max_length=512)
class Post(models.Model):
"""
An object for arbituary posts. Contains all post data, type, etc.
"""
quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
page_num = models.IntegerField(default=1)
POST_TYPES = (
('text', 'Text'),
('dice', 'Dice'),
2018-08-23 11:57:37 -04:00
('poll', 'Poll')
)
post_type = models.CharField(max_length=4, choices=POST_TYPES)
post_text = models.TextField()
timestamp = models.DateTimeField(auto_now=True)
2018-08-23 11:57:37 -04:00
class DiceCall(models.Model):
"""
An object representing dice calls made by the QM.
"""
post = models.OneToOneField(
Post,
on_delete=models.CASCADE,
primary_key=True,
)
dice_roll = models.CharField(max_length=9)
strict = models.BooleanField()
dice_challenge = models.IntegerField(
null=True,
blank=True,
validators=[
MaxValueValidator(999),
MinValueValidator(1)
]
)
rolls_taken = models.IntegerField(
null=True,
blank=True,
validators=[
MaxValueValidator(99),
MinValueValidator(1)
]
)
2018-08-29 14:01:31 -04:00
open = models.BooleanField()
2018-08-23 11:57:37 -04:00
2018-08-24 21:51:03 -04:00
class DiceRoll(models.Model):
"""
Represents a dice roll made on a valid dicecall.
"""
dicecall = models.ForeignKey(DiceCall, on_delete=models.CASCADE)
message = models.OneToOneField(
Message,
on_delete=models.CASCADE,
primary_key=True,
)
roll = models.CharField(max_length=9)
results = models.TextField()
total = models.IntegerField()
2018-08-29 14:01:31 -04:00
class Poll(models.Model):
"""
An object representing polls made by the QM.
"""
post = models.OneToOneField(
Post,
on_delete=models.CASCADE,
primary_key=True,
)
multi_choice = models.BooleanField()
allow_writein = models.BooleanField()
open = models.BooleanField()
class PollOption(models.Model):
"""
Represents options (choices) attached to a given poll. These can be
added by the QM upon creation, or by users through write-ins.
"""
poll = models.ForeignKey(Poll, on_delete=models.CASCADE)
text = models.CharField(max_length=200)
class PollVote(models.Model):
"""
Represents a user voting for an option.
"""
option = models.ForeignKey(PollOption, on_delete=models.CASCADE)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
2018-09-03 17:59:41 -04:00
on_delete=models.CASCADE,
blank=True,
null=True)
2018-08-29 14:01:31 -04:00
ip_address = models.GenericIPAddressField()
class Meta:
unique_together = ('option', 'ip_address')
2018-08-29 14:01:31 -04:00
class PageTitle(models.Model):
"""
Represents the title of a quest page.
"""
quest = models.ForeignKey(Quest, on_delete=models.CASCADE)
page_num = models.IntegerField()
title = models.CharField(max_length=200)
def __str__(self):
return self.title