from django.db import models from django.utils.translation import gettext_lazy as _ from sorl.thumbnail.fields import ImageField as SORLImageField from utils.methods import image_path from utils.models import ProjectBaseMixin, SORLImageMixin, PlatformMixin class ImageQuerySet(models.QuerySet): """QuerySet for model Image.""" class Image(ProjectBaseMixin, SORLImageMixin, PlatformMixin): """Image model.""" HORIZONTAL = 0 VERTICAL = 1 ORIENTATIONS = ( (HORIZONTAL, _('Horizontal')), (VERTICAL, _('Vertical')), ) image = SORLImageField(upload_to=image_path, verbose_name=_('image file')) parent = models.ForeignKey('self', blank=True, null=True, default=None, related_name='parent_image', on_delete=models.SET_DEFAULT, verbose_name=_('parent image')) orientation = models.PositiveSmallIntegerField(choices=ORIENTATIONS, blank=True, null=True, default=None, verbose_name=_('image orientation')) title = models.CharField(_('title'), max_length=255, default='') objects = ImageQuerySet.as_manager() class Meta: """Meta class.""" verbose_name = _('Image') verbose_name_plural = _('Images') def __str__(self): """String representation""" return str(self.id)