Skip to content

Commit 84cd131

Browse files
author
yangxueguang
committed
更新view获取分类,修正了一些模板的错误。
1 parent 96fce4d commit 84cd131

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

blog/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __str__(self):
2424
return self.title
2525

2626
class Meta:
27-
ordering = ['last_modified_time']
27+
ordering = ['-last_modified_time']
2828

2929

3030
class Category(models.Model):

blog/static/blog/css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ a.backToTop:hover {
538538
width:14px;
539539
height:13px;
540540
margin-right: 7px;
541-
background:url(img/date.png) no-repeat;
541+
background:url(../img/date.png) no-repeat;
542542
}
543543

544544

blog/templates/blog/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<div id="category-title">
55
<ul>
66
<li>分类:</li>
7-
<li class="cat-item"><a href="">111</a></li>
7+
{% for category in category_list %}
8+
<li class="cat-item"><a href="">{{ category.name }}</a></li>
9+
{% endfor %}
810
</ul>
911
</div>
1012
</div>
@@ -24,7 +26,7 @@ <h1 class="title"><a href="">{{ article.title }}</a></h1>
2426
<div class="post-ft">
2527
<a href="" class="more">阅读全文>></a>
2628
<i class="icon-date"></i>
27-
<span class="date">{{ article.last_modified_time }}</span>
29+
<span class="date">{{ article.last_modified_time|date:"Y年n月d日" }}</span>
2830
</div>
2931
</div>
3032
{% endfor %}

blog/views.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@ def get_queryset(self):
1414
for article in article_list:
1515
article.body = markdown2.markdown(article.body, )
1616
return article_list
17+
18+
def get_context_data(self, **kwargs):
19+
kwargs['category_list'] = Category.objects.all().order_by('name')
20+
return super(IndexView, self).get_context_data(**kwargs)

0 commit comments

Comments
 (0)