Commit 79451e84 authored by Jean Michel Rouly's avatar Jean Michel Rouly

Filter by date as well

parent 3730cfdb
......@@ -26,12 +26,16 @@ Homepage
</div>
{% endif %}
{% if sort == "comments" %}
{% if sort %}
<div class="row">
<div class="col-lg-10 col-lg-offset-1">
<div class="alert alert-dismissable alert-info text-center">
<button type="button" class="close" data-dismiss="alert">&times;</button>
Sorting questions with fewest comments first.
{% if sort == "comments" %}
<strong>Sorting questions with fewest comments first.</strong>
{% elif sort == "date" %}
<strong>Sorting questions most recently first.</strong>
{% endif %}
</div>
</div>
</div>
......
......@@ -59,6 +59,8 @@ def index(request, *args, **kwargs):
if sort is not None:
if sort == "comments":
questions = questions.annotate(comment_count=Count('comments')).order_by('comment_count')
if sort == "date":
questions = questions.order_by('-date')
paginator = Paginator(questions, 10) # show 25 questions per page
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment