2021-03-30 21:25:52 +02:00
|
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from django.db import models
|
|
|
|
from django.db.models import CASCADE
|
2021-03-31 01:10:04 +02:00
|
|
|
from django.urls import reverse
|
2021-03-30 21:25:52 +02:00
|
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
2021-03-31 01:10:04 +02:00
|
|
|
|
|
|
|
class StoryRound(models.Model):
|
|
|
|
name = models.CharField(max_length=256)
|
2021-04-19 00:17:35 +02:00
|
|
|
participants = models.ManyToManyField(User) # for ordering add: through='Participant'
|
2021-03-31 01:10:04 +02:00
|
|
|
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()
|
|
|
|
|
|
|
|
|
2021-03-30 21:25:52 +02:00
|
|
|
class Story(models.Model):
|
|
|
|
name = models.CharField(max_length=256, null=True, blank=True)
|
2021-03-31 01:10:04 +02:00
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
|
|
part_of_round = models.ForeignKey(StoryRound, on_delete=CASCADE)
|
|
|
|
started_by = models.ForeignKey(User, on_delete=CASCADE)
|
2021-03-30 21:25:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
class StoryPart(models.Model):
|
|
|
|
user = models.ForeignKey(User, on_delete=CASCADE)
|
2021-03-31 01:10:04 +02:00
|
|
|
previous_part = models.ForeignKey('StoryPart', on_delete=CASCADE, null=True, blank=True)
|
2021-03-30 21:25:52 +02:00
|
|
|
text = models.TextField()
|
2021-03-31 01:10:04 +02:00
|
|
|
part_of = models.ForeignKey('Story', on_delete=CASCADE)
|