from django.contrib.auth import get_user_model from django.db import models from django.db.models import CASCADE from django.urls import reverse User = get_user_model() class StoryRound(models.Model): name = models.CharField(max_length=256) participants = models.ManyToManyField(User) # for ordering add: through='Participant' created = models.DateTimeField(auto_now_add=True) number_of_rounds = models.IntegerField() def get_absolute_url(self): return reverse('writing:detail', kwargs={'pk': self.pk}) class Participant(models.Model): user = models.ForeignKey(User, on_delete=CASCADE) story_round = models.ForeignKey(StoryRound, on_delete=CASCADE) order_by = models.IntegerField() class Story(models.Model): name = models.CharField(max_length=256, null=True, blank=True) created = models.DateTimeField(auto_now_add=True) part_of_round = models.ForeignKey(StoryRound, on_delete=CASCADE) started_by = models.ForeignKey(User, on_delete=CASCADE) class StoryPart(models.Model): user = models.ForeignKey(User, on_delete=CASCADE) previous_part = models.ForeignKey('StoryPart', on_delete=CASCADE, null=True, blank=True) text = models.TextField() part_of = models.ForeignKey('Story', on_delete=CASCADE)