J
J
joli2019-03-15 17:08:57
Django
joli, 2019-03-15 17:08:57

How does the as argument work?

Please explain how it works

{% get_most_commented_posts as most_commented_posts %}
     <ul>
       {% for post in most_commented_posts %}
       <li>
          <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
      </li>
{% endfor %}
</ul>



def get_most_commented_posts(count=5):
       return Post.published.annotate(total_comments=Count('comments')).order_by('total_comments')[:count]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2019-03-15
@joli

Like an assignment.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question