From 73d81081c6faaa662f442b729648c64d6ef2dc55 Mon Sep 17 00:00:00 2001 From: Patrick Canterino Date: Sun, 30 Jan 2022 14:55:49 +0100 Subject: [PATCH] Now we can list the months in archive --- notes/templates/archive_year.html | 10 +++++++++- notes/views.py | 5 +++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/notes/templates/archive_year.html b/notes/templates/archive_year.html index ec64328..826086a 100644 --- a/notes/templates/archive_year.html +++ b/notes/templates/archive_year.html @@ -5,5 +5,13 @@ {% block content %}

Archive {{ year }}

- +{% if months %} + +{% else %} +

No notes

+{% endif %} {% endblock %} \ No newline at end of file diff --git a/notes/views.py b/notes/views.py index 2c6eb52..ef6414f 100644 --- a/notes/views.py +++ b/notes/views.py @@ -1,6 +1,6 @@ from django.shortcuts import render, get_object_or_404, redirect from django.core.paginator import Paginator -from django.db.models.functions import ExtractYear +from django.db.models.functions import ExtractYear, ExtractMonth from pcdenotes.settings import NOTES_PER_PAGE from .models import Note @@ -38,7 +38,8 @@ def archive_main(request): return render(request, 'archive_main.html', {'years': notes_years}) def archive_year(request, archive_year): - return render(request, 'archive_year.html', {'year': archive_year}) + notes_months = Note.objects.filter(status=1, created_at__year=archive_year).annotate(created_month=ExtractMonth('created_at')).values_list('created_month', flat=True).distinct().order_by('created_month') + return render(request, 'archive_year.html', {'year': archive_year, 'months': notes_months}) def archive_month(request, archive_year, archive_month): return render(request, 'archive_month.html', {'year': archive_year, 'month': archive_month}) \ No newline at end of file -- 2.34.1