Fix blog by year index.
Add an additional context data that is always the entire list of years, and use that instead of date_list for the current queryset.
This commit is contained in:
		
							parent
							
								
									9c090f2c27
								
							
						
					
					
						commit
						c7d4309149
					
				
					 2 changed files with 6 additions and 2 deletions
				
			
		|  | @ -61,6 +61,9 @@ def all_authors(): | ||||||
|     return sorted(Person.objects.filter(entry__isnull=False).distinct(), |     return sorted(Person.objects.filter(entry__isnull=False).distinct(), | ||||||
|                   key=last_name) |                   key=last_name) | ||||||
| 
 | 
 | ||||||
|  | def all_year_list(): | ||||||
|  |     return Entry.objects.dates(date_field, 'year') | ||||||
|  | 
 | ||||||
| # The functions are passed to the context uncalled so they will be | # The functions are passed to the context uncalled so they will be | ||||||
| # called for each web request.  If we want to only make these database | # called for each web request.  If we want to only make these database | ||||||
| # queries a single time when a web server process begins, call both | # queries a single time when a web server process begins, call both | ||||||
|  | @ -68,3 +71,4 @@ def all_authors(): | ||||||
| 
 | 
 | ||||||
| extra_context['all_authors'] = all_authors | extra_context['all_authors'] = all_authors | ||||||
| extra_context['all_tags'] = all_tags_by_use_amount | extra_context['all_tags'] = all_tags_by_use_amount | ||||||
|  | extra_context['all_year_list'] = all_year_list | ||||||
|  |  | ||||||
|  | @ -24,10 +24,10 @@ | ||||||
| (<a href="/feeds/blog/?tag={{ tag.slug }}">rss</a>)</li> | (<a href="/feeds/blog/?tag={{ tag.slug }}">rss</a>)</li> | ||||||
| {% endfor %} | {% endfor %} | ||||||
| </ul> | </ul> | ||||||
| {% if date_list %} | {% if all_year_list %} | ||||||
| <h2>Blog Index by Year</h2> | <h2>Blog Index by Year</h2> | ||||||
| <ul> | <ul> | ||||||
| {% for year in date_list reversed %}<li><a href="{{ year|date:"Y" }}/">{{ year|date:"Y" }}</a></li>{% endfor %} | {% for year in all_year_list reversed %}<li><a href="{{ year|date:"Y" }}/">{{ year|date:"Y" }}</a></li>{% endfor %} | ||||||
| </ul> | </ul> | ||||||
| {% endif %} | {% endif %} | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Bradley M. Kuhn
						Bradley M. Kuhn