include week in archive view
This commit is contained in:
parent
6efa5b7900
commit
5c4cc4e7b2
2 changed files with 9 additions and 2 deletions
|
@ -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):
|
||||
|
|
|
@ -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 %}
|
||||
|
|
Loading…
Reference in a new issue