diff --git a/idescriptor/models.py b/idescriptor/models.py index bb794a5..593e9a2 100644 --- a/idescriptor/models.py +++ b/idescriptor/models.py @@ -7,6 +7,7 @@ from django.db import models 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 imagebot import settings @@ -61,3 +62,13 @@ class Image(models.Model): file_hash=file_hash ) os.remove(path) + + @staticmethod + def get_image_for_descriptor(): + image = Image.objects.filter(Q(alt_text=None) | Q(title=None)).first() + return image + + @staticmethod + def get_image_to_post(): + image = Image.objects.filter(Q(alt_text__isnull=False) & Q(title__isnull=False)).first() + return image diff --git a/idescriptor/views.py b/idescriptor/views.py index 0f5dde8..1be65da 100644 --- a/idescriptor/views.py +++ b/idescriptor/views.py @@ -5,13 +5,8 @@ from django.urls import reverse from idescriptor.forms import ImageForm from idescriptor.models import Image -from django.db.models import Q -def get_image_for_descriptor(): - image = Image.objects.filter(Q(alt_text=None) | Q(title=None)).first() - return image - def list_images(request): images = Image.objects.all() context = {"images": images} @@ -29,7 +24,7 @@ class ImageFormView(UpdateView): def index(request): """View function for home page of site.""" - image_to_describe = get_image_for_descriptor() + image_to_describe = Image.get_image_for_descriptor() if request.method == "POST": action = request.POST.get("action")