2012-07-21 65 views

回答

6

從Django文檔:

You can loop over a list in reverse by using {% for obj in list reversed %}. 

所以,在我的模板,我有:

{% for comment in comment_list reversed %} 

您的意見現在在反向。

0

您可以嘗試https://docs.djangoproject.com/en/dev/ref/contrib/comments/custom/

class ReorderComment(Comment): 
    class Meta: 
     ordering = ["-submit_date"] 

在settings.py

COMMENTS_APP = 'my_comment_app' 

或者您也可以通過創建創建一個templatetags

{% get_comment_list for event as comment_list %} 
{% reoder_comments comment_list as reodered_comment_list %} 

的reoder templatetags會看起來像reoder他們(用django-classy-tags)

register = template.Library() 
class ReoderComments(Tag): 
    name = 'reoder_comments' 
    options = Options(
     Argument('queryset'), 
     'as', 
     Argument('varname', required=False, resolve=False) 
    ) 
    def render_tag(self, context, queryset, varname): 
     context[varname] = queryset.order_by("-submit_date") 
     return '' 
register.tag(ReoderComments) 
+0

使用templatetag方法,我現在收到一個錯誤,提示「Exception Value:name'Tag'未定義」。你能否提供進一步的指導? – cjohnston 2012-07-23 22:05:20