2

我目前正在尝试使用重组模板标签按发布年份排序博客文章发布日期列表。

我传递到我的上下文中以重新组合的查询集是:

 'post_archive_months': Post.objects.published().\
 filter(site__id=settings.SITE_ID).dates('publish','month').reverse(),

在模板中,我这样称呼它:

<section class="blog_archive_block">
  <h4>Blog Archive</h4>
    {% regroup post_archive_months by year as post_archive_dates %}
    <ul class="" id="">
      {% for year in post_archive_dates %}
      <li>
        <div class="header_box">
          <h4>{{year.grouper}} <a href="#" class="arrow_up"></a></h4>
        </div>
        <div class="content_box">
          <ul class="month">
          {% for month in year.list %}
            <li>
              <a href="/blog/{{year.grouper}}/{{month|date:'M'}}">{{month|date:"F"}}</a>
            </li>
          {% endfor %}
          </ul>
        </div>
      </li>
      {% endfor %}
    </ul>
</section> 

返回的数据是:

[{'list': [[datetime.datetime(2012, 9, 1, 0, 0, tzinfo=<UTC>), datetime.datetime(2012, 5,    
1, 0, 0, tzinfo=<UTC>), datetime.datetime(2012, 4, 1, 0, 0, tzinfo=<UTC>), 
datetime.datetime(2011, 10, 1, 0, 0, tzinfo=<UTC>), datetime.datetime(2011, 8, 1, 0, 0,   
tzinfo=<UTC>)]], 'grouper': None}]

我原以为石斑鱼会是一年,或者至少是 None 类型之外的东西,但情况似乎并非如此。

如果您需要我提供更多信息,请告诉我。谢谢!

4

0 回答 0