From: Patrick Canterino Date: Sun, 30 Jan 2022 13:55:49 +0000 (+0100) Subject: Now we can list the months in archive X-Git-Url: https://git.p6c8.net/pcdenotes.git/commitdiff_plain/73d81081c6faaa662f442b729648c64d6ef2dc55 Now we can list the months in archive --- 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