fix: Set image as posted, get last posted image first

This commit is contained in:
moanos [he/him] 2024-10-22 00:11:00 +02:00
parent e02ec77308
commit 791330e415

View File

@ -8,7 +8,7 @@ from django.urls import reverse
from django.core.files import File from django.core.files import File
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.db.models import Q from django.db.models import Q
from datetime import datetime from django.utils import timezone
from imagebot import settings from imagebot import settings
@ -45,7 +45,8 @@ class Image(models.Model):
def set_image_posted(self): def set_image_posted(self):
self.number_times_posted += 1 self.number_times_posted += 1
self.last_posted = datetime.now() self.last_posted = timezone.now()
self.save()
@staticmethod @staticmethod
def consume(): def consume():
@ -70,5 +71,5 @@ class Image(models.Model):
@staticmethod @staticmethod
def get_image_to_post(): 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 return image