Skip to content

Instantly share code, notes, and snippets.

@mumin91
Created March 25, 2020 16:26
Show Gist options
  • Select an option

  • Save mumin91/f74d5b01290c0b9423a052ffb7658f52 to your computer and use it in GitHub Desktop.

Select an option

Save mumin91/f74d5b01290c0b9423a052ffb7658f52 to your computer and use it in GitHub Desktop.
Recursive chain comment model in Django
class Comment(models.Model):
comment = models.CharField(max_length=300)
blogpost = models.ForeignKey(Blogpost, on_delete=models.CASCADE)
commenter = models.ForeignKey(get_user_model(), on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
parent = models.ForeignKey('self', null=True, blank=True, related_name='replies', on_delete=models.CASCADE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment