I'm trying to design a Django model for articles with attributes like title, publication date, etc. One of the attributes is other article(s) that the article in question is commenting on. I'm not sure how to code this since there is no foreign key involved - I just want a reference to other instances of the Article model (i.e. one or more other articles). This is what I have so far:
class Article(models.Model):
    title = models.CharField(max_length=400)
    publication_date = date_published = models.DateField()
    comment_on = ?????????????
Any suggestions would be much appreciated. Thank you!
I think you should user ForeignKey
 comment_on = models.ForeignKey('self',null=True,blank=True)
To create a recursive relationship -- an object that has a many-to-one relationship with itself -- use models.ForeignKey('self').
Django foreign key docs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With