2017-07-15 18:13:45 +02:00
|
|
|
from django.db import models
|
|
|
|
from django.contrib.auth.models import User
|
2017-07-15 21:22:15 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2017-07-15 18:13:45 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Notifying(models.Model):
|
|
|
|
subscribed = models.ManyToManyField(
|
|
|
|
User,
|
|
|
|
verbose_name=_("abonnés"),
|
|
|
|
related_name="subscribed_to"
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_url(self, *args, **kwargs):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Notification(models.Model):
|
2017-07-15 21:22:15 +02:00
|
|
|
sent_by = models.ForeignKey(
|
|
|
|
Notifying,
|
|
|
|
related_name="notifs_sent"
|
|
|
|
)
|
|
|
|
about = models.ForeignKey(
|
|
|
|
Notifying,
|
|
|
|
related_name="notifs",
|
|
|
|
)
|
2017-07-15 18:13:45 +02:00
|
|
|
to = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
verbose_name=_("envoyée à")
|
|
|
|
)
|
|
|
|
viewed_at = models.DateTimeField(
|
|
|
|
_("Vue à"),
|
|
|
|
blank=True
|
|
|
|
)
|
|
|
|
text = models.TextField(_("corps de la notification"))
|
2017-07-15 18:37:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Commentable(Notifying):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class Thread(models.Model):
|
2017-07-15 21:22:15 +02:00
|
|
|
topic = models.OneToOneField(Commentable)
|
2017-07-15 18:37:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Comment(models.Model):
|
|
|
|
thread = models.ForeignKey(Thread)
|
|
|
|
parent = models.ForeignKey(
|
|
|
|
'Comment',
|
|
|
|
related_name="replies",
|
|
|
|
)
|
|
|
|
author = models.ForeignKey(
|
|
|
|
User,
|
|
|
|
verbose_name=_("auteur"),
|
|
|
|
editable=False
|
|
|
|
)
|
|
|
|
at = models.DateTimeField(
|
|
|
|
_("date d'écriture"),
|
|
|
|
auto_now_add=True
|
|
|
|
)
|
|
|
|
text = models.TextField(_("corps du message"))
|