回到顶部

阅读目录

django 按年月日归档

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>

 

^_^
请喝咖啡 ×

文章部分资料可能来源于网络,如有侵权请告知删除。谢谢!

前一篇: xadmin 安装方法导致 theme 插件应用失败,暂时未知原因
下一篇: 网站 http 资源切换成 https
captcha