/
models.py
27 lines (19 loc) · 995 Bytes
/
models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from django.db import models
from django.contrib.auth.models import User
from della.utils import TimeStampMixin
class Thread(TimeStampMixin):
"""
`is_sneaky` flag will be used when the message thread is between santa and
santee. If `is_sneaky` is set to `True` then `santa` shouldn't be null.
`participant_1.id` will be always less than `participant_2.id`
"""
is_sneaky = models.BooleanField(default=False)
participant_1 = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='participant_1_threads')
participant_2 = models.ForeignKey(
User, on_delete=models.CASCADE, related_name='participant_2_threads')
santa = models.ForeignKey(User, on_delete=models.CASCADE, null=True, related_name='santa_threads')
class Message(TimeStampMixin):
text = models.TextField()
sent_by = models.ForeignKey(User, on_delete=models.CASCADE)
thread = models.ForeignKey(Thread, on_delete=models.CASCADE, related_name='messages')