D
D
Domohod2022-02-18 20:19:26
Django
Domohod, 2022-02-18 20:19:26

How to fix 'Comment' object is not reversible?

I need to display the comments in reverse order, but Django doesn't allow for looping, so I write the view like this:

class Comment2(TemplateView):
    template_name = "registration/comments.html"


    def get_context_data(self, **kwargs):
        context = super().get_context_data(**kwargs)
        comment = Comment.objects.get(pk=1)
        conversely = reversed(comment)
        context['comment'] = comment
        context['conversely'] = conversely
        return context


comments are rendered in the template:
{% for item in conversely %}

But an error is raised:
'Comment' object is not reversible
line: conversely = reversed(comment)


Help, how can I fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Domohod, 2022-02-19
@Domohod

everything is really simple.
reversed is simple enough to write in the template.
{% for item in comments reversed %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question