在 Mezzanine 的侧面板中添加最近的评论

Adding Recent Comments in a side panel in Mezzanine

我创建了一个左侧面板,除了其他内容(例如最近的帖子)之外,还包含一个显示最近评论的部分。 我很难完成这项工作。 这是我到目前为止尝试过的:

{% load comment_tags %}
...
{% block recent_comments %}
{% recent_comments 5 as last_comments %}
{% if last_comments %}
...
{% endif %}
{% endblock %}

但我在第 {% recent_comments 5 as last_comments %}

行收到 VariableDoesNotExist 错误

如何实现这样的 "Recent Comments" 部分?

谢谢,

GG

你从哪里得到这个代码? Mezzanine 的 recent_comments 标签是一个以不同方式工作的包含标签:

{% recent_comments %}

并且您应该在 settings.py 中定义 COMMENT_NUM_LATEST 设置。

如果您想获取最后评论的列表,则必须创建自定义 assignment template tag:

from mezzanine import template
from mezzanine.generic.models import ThreadedComment

register = template.Library()

@register.assignment_tag
def get_recent_comments(num):
    return ThreadedComment.objects.all().select_related(depth=1) \
                                  .order_by("-id")[:num]