From 791330e41559dfb6b1e5706d29940b747017c3d2 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 22 Oct 2024 00:11:00 +0200 Subject: [PATCH] fix: Set image as posted, get last posted image first --- idescriptor/models.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/idescriptor/models.py b/idescriptor/models.py index 593e9a2..a8e1135 100644 --- a/idescriptor/models.py +++ b/idescriptor/models.py @@ -8,7 +8,7 @@ from django.urls import reverse from django.core.files import File from django.utils.translation import gettext_lazy as _ from django.db.models import Q -from datetime import datetime +from django.utils import timezone from imagebot import settings @@ -45,7 +45,8 @@ class Image(models.Model): def set_image_posted(self): self.number_times_posted += 1 - self.last_posted = datetime.now() + self.last_posted = timezone.now() + self.save() @staticmethod def consume(): @@ -70,5 +71,5 @@ class Image(models.Model): @staticmethod def get_image_to_post(): - image = Image.objects.filter(Q(alt_text__isnull=False) & Q(title__isnull=False)).first() + image = Image.objects.filter(Q(alt_text__isnull=False) & Q(title__isnull=False)).order_by('last_posted').first() return image