S
S
Sergey Nizhny Novgorod2016-08-18 09:52:27
Django
Sergey Nizhny Novgorod, 2016-08-18 09:52:27

How to bind a comment model to itself?

Hello. Situation:
1) There is a forum topic model: ForumTheme

class ForumTheme(models.Model):
    user_link = models.ForeignKey(User, on_delete=models.CASCADE, default=1)
    forum_category = models.CharField(max_length=200)   
    title = models.CharField(max_length=200)
    forum_text = models.TextField()

2) There is a comment model for this topic: ForumCom
class ForumCom(models.Model):
    forum_connect = models.ForeignKey(ForumTheme, on_delete=models.CASCADE, default=1)
    user_link = models.ForeignKey(User, on_delete=models.CASCADE, default=1)    
    forumcom_body = models.TextField()

3) I am now doing a reply to a comment. Those. another user clicks on the reply button below the comment and replies to that comment. And I don't know how to fix it. In theory, it should be something like:
class ForumCom(models.Model):
    forum_connect = models.ForeignKey(ForumTheme, on_delete=models.CASCADE, default=1)
    user_link = models.ForeignKey(User, on_delete=models.CASCADE, default=1)    
    forumcom_body = models.TextField()    
    answer_connect = models.ForeignKey(ForumCom, on_delete=models.CASCADE, default=1)

But Django doesn't let the model bind to itself. How can I do that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Kitaev, 2016-08-18
@Terras

ForeignKey('self')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question