include week in archive view

This commit is contained in:
j 2023-08-16 17:58:28 +02:00
parent 6efa5b7900
commit 5c4cc4e7b2
2 changed files with 9 additions and 2 deletions

View file

@ -7,6 +7,7 @@ import lxml.html
from django.conf import settings
from django.contrib.auth import get_user_model
from django.db import models
from django.db.models.functions import ExtractWeek, ExtractYear
from django.urls import reverse
from django.utils.timesince import timesince
@ -64,7 +65,6 @@ class Item(models.Model):
cal = now.date().isocalendar()
monday = now.date() - timedelta(days=now.date().isocalendar().weekday - 1)
monday = timezone.datetime(monday.year, monday.month, monday.day, tzinfo=now.tzinfo)
print(monday)
first_post = qs.filter(published__gt=monday).first()
if first_post and first_post.published < now:
week = qs.filter(published__gt=monday)
@ -76,7 +76,11 @@ class Item(models.Model):
else:
last_monday = monday - timedelta(days=7)
week = qs.filter(published__gt=last_monday)
archive = qs.exclude(id__in=week)
archive = (qs
.exclude(id__in=week)
.annotate(year=ExtractYear('published'))
.annotate(week=ExtractWeek('published'))
)
return week, archive
def get_absolute_url(self):

View file

@ -1,6 +1,9 @@
{% extends "base.html" %}
{% block content %}
{% for item in items %}
{% ifchanged item.week %}
<h2>{{ item.year }} week {{ item.week }}</h2>
{% endifchanged %}
{% include "listitem.html" with item=item %}
{% endfor %}
{% endblock %}