geschichten/stories/writingtogether/models.py

37 lines
1.2 KiB
Python
Raw Normal View History

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
from django.urls import reverse
2021-03-30 21:25:52 +02:00
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()
2021-03-30 21:25:52 +02:00
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)
2021-03-30 21:25:52 +02:00
class StoryPart(models.Model):
user = models.ForeignKey(User, on_delete=CASCADE)
previous_part = models.ForeignKey('StoryPart', on_delete=CASCADE, null=True, blank=True)
2021-03-30 21:25:52 +02:00
text = models.TextField()
part_of = models.ForeignKey('Story', on_delete=CASCADE)