[Answer]-How to reverse link foreign key in Django model?

1👍

You are doing it backwards. If you want to have a parent_thread, you have to put the ForeignKey into the Comment class, not vice versa like this:

class Thread(models.Model):
    ...

class Comment (models.Model):
    parent_thread = models.ForeignKey(Thread)
    ...

In your current code you have multiple Thread objects linked to a single Comment object.

👤Selcuk

Leave a comment