Answer the question
In order to leave comments, you need to log in
Django mptt comments?
Good day. I'm new to Django, I decided to deal with mptt and upload my comment system to the site.
models:
class Comment(MPTTModel):
comment = models.CharField(max_length=50, unique=True)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
class MPTTMeta:
order_insertion_by = ['comment']
def __str__(self):
return self.comment
class Article(models.Model):
db_table = 'article'
ordering = ['article_date']
verbose_name = 'Статья'
verbose_name_plural = 'Статьи'
article_title = models.CharField(max_length=50)
comment = models.ForeignKey(Comment, null=True, blank=True, related_name='com')
def show_comment(request):
return render(request, "comments.html")
def article(reques, article_id):
args ={}
args['article'] = Article.objects.get(id=article_id)
args['comments'] = Comment.objects.all()
return render(request, 'article.html', args)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question