I am working on a django project following an old guide from CoreyMSchafer (https://www.youtube.com/watch?v=UmljXZIypDc&list=PL-osiE80TeTtoQCKZ03TU5fNfx2UY6U4p), who builds a django blog application. After finishing the tutorial he created I wanted to take it a step further. In the videos he creates posts, but he does not create a way for users to comment. I want to add this, but am running into a bit of idea block. My first thought is to continue the method he employed for the posts, which would be establish a one to many relationship with the user and the post, as below.
class Post(models.Model):
title = models.CharField(max_length=100)
content = models.TextField(max_length=1200)
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User, on_delete=models.CASCADE)
def __str__(self):
return self.title
def get_absolute_url(self):
return reverse('post-detail', kwargs={'pk': self.pk})
class Comment(models.Model):
title = models.CharField(max_length=100)
content = models.TextField(Max_length=1200)
date_posted = models.DateTimeField(default=timezone.now)
author = models.ForeignKey(User,on_delete=models.CASCADE)
base_post = models.ForeignKey(Post, on_delete=models.CASCADE)
def __str__(self):
return self.title
my concern with this would be that django does not support multiple many to one relationships, any thoughts and ideas are helpful.