A
A
Ayaks772017-04-12 22:12:49
Django
Ayaks77, 2017-04-12 22:12:49

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')

view:
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)

I can’t figure out how to attach a comment thread to an article so that it can be filtered by id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2017-04-12
@Ayaks77

https://docs.djangoproject.com/en/1.10/ref/models/...
Think what is wrong in the following code

comments_article
article_title

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question