use make_aware

This commit is contained in:
j 2023-08-14 23:30:57 +02:00
parent a90914fa8e
commit c192f91a03

View file

@ -59,11 +59,12 @@ class Item(models.Model):
@classmethod
def public(cls, now=None):
if now is None:
now = timezone.now()
now = timezone.make_aware(datetime.now(), timezone.get_default_timezone())
qs = cls.objects.exclude(published=None).filter(published__lte=now).order_by('-published')
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)