#!/usr/bin/env python3 """ The main quest models. """ from django.db import models from django.conf import settings from django.core.validators import MaxValueValidator, MinValueValidator 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) 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'), ('poll', 'Poll') ) post_type = models.CharField(max_length=4, choices=POST_TYPES) post_text = models.TextField() timestamp = models.DateTimeField(auto_now=True) 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) ] ) open = models.BooleanField(default=False) 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() 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