class Thread(models.Model):
user = models.ManyToManyField(User)
is_hidden = models.ManyToManyField(User, related_name='hidden_thread', blank=True)
def __unicode__(self):
return unicode(self.id)
class Message(models.Model):
thread = models.ForeignKey(Thread)
sent_date = models.DateTimeField(default=datetime.now)
sender = models.ForeignKey(User)
body = models.TextField()
is_hidden = models.ManyToManyField(User, related_name='hidden_message', blank=True)
def __unicode__(self):
return "%s - %s" % (unicode(self.thread.id), self.body)
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/495305343-1386058174-cardhu_decombobulator_blackberry.rim.net-1176089190-%40b17.c3.bise7.blackberry.
from django.db.models.signals import post_save
from django.dispatch import receiver
from myapp.models import Message, Thread
@receiver(post_save, sender=Message) def add_to_thread(sender, instance, created, **kwargs): if created:
instance.thread.user.add(instance.sender)
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/7e351773-8a47-4c04-8795-6d71e4746bf0%40googlegroups.com.