If I understand what you are building. You want some way to group
messages into threads? I assume that a Thread will have many messages?
Unless I am missing something you might want something like this:
class Thread(models.Model):
subject = models.CharField(max_length=256)
class Message(models.Model):
thread = models.ForeignKey(Thread)
sent_date = models.DateTimeField(default=datetime.now)
body = models.TextField()
user = models.ForeignKey(User)
Then you can create a filter for the Thread based on a subject:
selected_subject = Thread.objects.filter(subject="some subject")
Then when you create the message you can use thread =
selected_subject[0] (assuming unique subjects/threads) when you create
your message. OR if 'some subject' isn't found, len(selected_subject)
== 0 then create a new Thread.
HTH,
Tim
>
https://groups.google.com/d/msgid/django-users/CAHSNPWt14jxduA_kT-Yxj-7k02qZzZkvkbfYU2pEPFghbNq%3DEg%40mail.gmail.com.