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