xkos / micolog

Automatically exported from code.google.com/p/micolog
MIT License
0 stars 0 forks source link

文章置顶有问题 #104

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
现在blog.py中输出到index.html中的属性只有满足条件的entries(��
�前页的所有文章),所以在模板中通过sticky过滤时,只能置�
��当前选出来的entries中的指定文章,而不能选出所有置顶文��
�。

额……可能说的有点乱。总之就是现在置顶有问题。

我试着解决了一下,可以通过在blog.py中MainPage类的doget方法中
新增加一个属性
stickys = Entry.all().filter('entrytype =','post').\
    filter("published =", True).filter("sticky =", True).order('-date')

来实现选出所有置顶文章,然后在加入return 
self.render('index',{'entries':entries,
    'stickys' : stickys,
    'show_prev' : show_prev,
        ……

然后模板中就可以通过增加stickys来实现,输出所有文章了。

Original issue reported on code.google.com by qhm...@gmail.com on 14 Oct 2010 at 11:20

GoogleCodeExporter commented 8 years ago
我理解的置顶好像没有那么复杂. 就是按sticky排序嘛. 
我在默认的按日期排序下, 增加了一个按sticky的排序方式. 
只改blog.py中的一行, 还是在doget方法中:
        entries = Entry.all().filter('entrytype =','post').\
                filter("published =", True).order('-sticky').order('-date').\
                fetch(self.blog.posts_per_page, offset = (page-1) * self.blog.posts_per_page)

不需要改任何模板, 因为都是默认用的是entries这个集合. 
结果就是sticky的post一定先出来排在页面上面. 
下面才是按日期排序(默认)的其他文章. 
如果我理解的置顶是这个意思, 那么这应该是正解.

Original comment by geo...@gmail.com on 26 Jun 2011 at 12:48

GoogleCodeExporter commented 8 years ago
补充一下, 
部署完毕第一次跑的时候有个报错说你的索引没有更新, 
然后错误的最后很体贴的给了你应该新建的索引代码. 
这几行粘贴到index.yaml文件最后. 再部署一次应该就好了.

Original comment by geo...@gmail.com on 26 Jun 2011 at 12:53