PonyConf/conversations/models.py

32 lines
856 B
Python
Raw Normal View History

2016-06-13 00:00:30 +00:00
from django.db import models
2016-06-14 19:39:04 +00:00
from django.contrib.auth.models import User
2016-06-12 21:39:04 +00:00
2016-06-14 19:39:04 +00:00
from accounts.models import Participation
from .utils import generate_message_token
2016-06-12 21:39:04 +00:00
class Conversation(models.Model):
2016-06-14 19:39:04 +00:00
participation = models.OneToOneField(Participation, related_name='conversation')
2016-06-12 21:39:04 +00:00
subscribers = models.ManyToManyField(User, related_name='+')
def __str__(self):
2016-06-14 19:39:04 +00:00
return "Conversation with %s" % self.participation.user
2016-06-13 00:00:30 +00:00
2016-06-12 21:39:04 +00:00
class Message(models.Model):
conversation = models.ForeignKey(Conversation, related_name='messages')
2016-06-14 19:39:04 +00:00
token = models.CharField(max_length=64, default=generate_message_token)
2016-06-12 21:39:04 +00:00
author = models.ForeignKey(User)
date = models.DateTimeField(auto_now_add=True)
content = models.TextField()
class Meta:
ordering = ['date']
def __str__(self):
return "Message from %s" % self.author