File tree Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Expand file tree Collapse file tree 3 files changed +7
-14
lines changed Original file line number Diff line number Diff line change 7
7
# Create your models here.
8
8
class ArticleManage (models .Manager ):
9
9
def archive (self ):
10
- date_list = Article .objects .datetimes ('created_time' , 'month' )
10
+ date_list = Article .objects .datetimes ('created_time' , 'month' , order = 'DESC' )
11
11
date_dict = defaultdict (list )
12
12
for d in date_list :
13
- print (type (d .year ))
14
- print (type (d .month ))
15
13
date_dict [d .year ].append (d .month )
16
- return dict (date_dict ) # 模板不支持defaultdict
14
+ return sorted (date_dict . items (), reverse = True ) # 模板不支持defaultdict
17
15
18
16
19
17
class Article (models .Model ):
Original file line number Diff line number Diff line change @@ -49,21 +49,16 @@ <h1 class="title"><a
49
49
<!-- tags -->
50
50
< h3 > 标签:</ h3 >
51
51
< div class ="list-group ">
52
- < a href ="# " class ="list-group-item "> < span class ="badge "> 14</ span > Cras justo odio</ a >
53
- < a href ="# " class ="list-group-item "> < span class ="badge "> 14</ span > Dapibus ac facilisis in</ a >
54
- < a href ="# " class ="list-group-item "> < span class ="badge "> 14</ span > Morbi leo risus</ a >
55
- < a href ="# " class ="list-group-item "> < span class ="badge "> 14</ span > Porta ac consectetur ac</ a >
56
- < a href ="# " class ="list-group-item "> < span class ="badge "> 14</ span > Vestibulum at eros</ a >
57
52
{% for tag in tag_list %}
58
- < a href ="{% url 'blog:tags ' tag.pk %} " class ="list-group-item "> < span
59
- class ="badge "> 14 </ span > {{ tag.name }}</ a >
53
+ < a href ="{% url 'blog:tag ' tag.pk %} " class ="list-group-item "> < span
54
+ class ="badge "> </ span > {{ tag.name }}</ a >
60
55
{% endfor %}
61
56
</ div >
62
57
63
58
<!-- archive -->
64
59
< h3 > 文章归档:</ h3 >
65
60
< div class ="panel-group " id ="accordion " role ="tablist " aria-multiselectable ="true ">
66
- {% for year,months in date_archive.items %}
61
+ {% for year,months in date_archive %}
67
62
< div class ="panel panel-default ">
68
63
< div class ="panel-heading " role ="tab " id ="heading{{ forloop.counter }} ">
69
64
< h4 class ="panel-title ">
@@ -78,7 +73,7 @@ <h4 class="panel-title">
78
73
aria-labelledby ="heading{{ forloop.counter }} ">
79
74
< div class ="panel-body ">
80
75
{% for month in months %}
81
- {{ month }} 月
76
+ < p > {{ month }} 月</ p >
82
77
{% endfor %}
83
78
</ div >
84
79
</ div >
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ def get_queryset(self):
19
19
def get_context_data (self , ** kwargs ):
20
20
kwargs ['category_list' ] = Category .objects .all ().order_by ('name' )
21
21
kwargs ['date_archive' ] = Article .objects .archive ()
22
- print ( kwargs ['date_archive' ] )
22
+ kwargs ['tag_list' ] = Tag . objects . all (). order_by ( 'name' )
23
23
return super (IndexView , self ).get_context_data (** kwargs )
24
24
25
25
You can’t perform that action at this time.
0 commit comments