Django评论,如何添加?

时间:2018-04-08 15:58:37

标签: django django-comments

我有一个Post模型:

class Post(models.Model):
    STATUS_CHOICES = (
        ("draft", "Draft"),
        ("published", "Published"),
        )
    title = models.CharField(max_length=250)
    slug = models.SlugField(max_length=250,
                            unique_for_date="publish")
    author = models.ForeignKey(User,
                               related_name="blog_posts",
                               on_delete=models.CASCADE)
    tag = models.ManyToManyField(Tag, related_name="blog_tag",
                            blank=True)
    body = models.TextField()
    publish = models.DateTimeField(default=timezone.now)
    created = models.DateTimeField(auto_now_add=True)
    updated = models.DateTimeField(auto_now=True)
    status = models.CharField(max_length=10,
                              choices=STATUS_CHOICES,
                              default="draft")
    image = models.ImageField(upload_to="blog/%Y/%m/%d",
                              blank=True)

    class Meta:
        ordering = ("-publish",)

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("blog:post_detail",
                       args=[self.publish.year,
                             self.publish.strftime("%m"),
                             self.publish.strftime("%d"),
                             self.slug])

我希望让用户添加评论,我该怎么做?我是否必须使用github的django-comments-xtd,或者更好地自己编写app?我需要一些我必须做的例子。

0 个答案:

没有答案