view.py
class TimlelineView(generic.ListView):
model = Article
template_name = 'timeline.html'
context_object_name = "article"
def get_queryset(self):
author_name = self.kwargs['author_name']
article_list = Article.objects.filter(show_status=True).order_by("-time_created")
return article_list
or
def timeline(request):
article_list = Article.objects.filter(show_status=True).order_by("-time_created")
return render(request, "timeline.html", locals())
timeline.html
<div class="am-g am-g-fixed blog-fixed blog-content">
<div class="am-u-sm-12">
<h1 class="blog-text-center">-- 存档 --</h1>
{# {{ article_list }}#}
{% regroup article_list by time_created.year as year_post_group %}
{% for year in year_post_group %}
<div class="timeline-year">
<h1>{{ year.grouper }}年</h1>
<hr>
{% regroup year.list by time_created.month as month_post_group %}
<ul>
{% for month in month_post_group %}
<h2>{{ month.grouper }}月</h2>
<hr>
{% regroup month.list by time_created.day as day_post_group %}
{% for day in day_post_group %}
<div class="timeline-day">
{{ day.grouper }}日
<ul>
{% for article in day.list %}
<li>
<a href="{% url "blog:detail" article.id %}">{{ article.title }}</a>
</li>
{% endfor %}
</ul>
</div>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endfor %}
</div>
</div>