Hello, please have a look at my models.py.
models.py:
class Thread(models.Model):
pass
class ThreadParticipant(models.Model):
thread = models.ForeignKey(Thread)
user = models.ForeignKey(User)
class Message(models.Model):
thread = models.ForeignKey(Thread)
sent_date = models.DateTimeField(default=datetime.now)
body = models.TextField()
user = models.ForeignKey(User)
class MessageReadState(models.Model):
message = models.ForeignKey(Message)
user = models.ForeignKey(User)
read_date = models.DateTimeField()
I am having two problems when I try to create a new message:
- How do I auto populate the Thread with its primary key whenever I create a new message, without manually creating a new thread?
- How to create a new user if the user is not in the the ThreadParticipant, or else don't create a new user?
I think I can solve this all in the views.py, but I think it will be better to solve this in the models.py. Please help me solve the problem. I would be very grateful. Thank you.
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/CAHSNPWsLC1LW1pqpYe-FUmC4k4twxBV8HrLxRex4e6VNicoBdQ%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.
No comments:
Post a Comment