get_comment_list reversed

Январь 23, 2010

Django has comments application and it works fine for me, except that I need comments in the reversed order. I could have used reversed order in the {% for %} tag, but this doesn’t work with pagination as pagination wants already prepared list. So I wrote a separate filter:

from django.template import Library

register = Library()
def reverse(value):
	return value

As this tag reverses the value that receives — all I need is to call this filter in any tag before use comments in pagination, e.g. {% if %}

	{% get_comment_list for object as comments %}
	{% if comments|reverse %}
	{% endif %}
	{% autopaginate comments 10 %}

That’s it!

tags: , ,
posted in Web by dmitko

5 Comments to "get_comment_list reversed"

  1. Ben wrote:

    Brilliant! Thanks very much for this elegant solution.

  2. dmitko wrote:

    :) you are welcome!

  3. Bernardo wrote:

    I crafted a custom solution by changing pagination code. If I use a negative value for pagination (-10 for example), it reverses the list.

    Open up and go to render()
    Find where value is defined (the 2nd line of render), add below it
    # If pagination is negative, reverse it
    if paginate_by < 0:
    paginate_by = -paginate_by

  4. Mike wrote:

    I am looking for a way so when the author logs into wordpress they only see comments left on their posts and no other comments. I mean in the control panel / dashboard area not on the post itself.


  5. RutheNAmelio wrote:

    Marvelous, what a webpage it is! This webpage provides helpful facts to us, keep it up.

Powered by Wordpress and MySQL. Theme by Shlomi Noach,