Monday, December 2, 2013

Save the user from one model to the another model

What I want to do is, whenever I create a new message, I want the sender of the Message to be added to the user of the Thread. How do I do that?
 
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)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAHSNPWveL8rqDLenDLayGrtC_RAwQ-Pfp0SYravr7%2BuJzhBhXw%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment