Titivillus/quest/models.py

89 lines
2.0 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)
open_post_id = models.IntegerField(null=True)
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)
]
)
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
2018-08-23 11:57:37 -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)