class UploadImage(models.Model):
    """ Модель картинки, загружаемой на сайт пользователем """
    image = models.ImageField('файл изображения', upload_to='images/%Y/%m/%d')
    description = models.TextField('Комментарий к изображению')
    created = models.DateField('Время создания объекта в БД', auto_now_add=True, db_index=True)
    exif = ExifField(source='image',)
    coordinates = models.CharField('Геоданные снимка', max_length=200, null=True)
    social_activity = models.CharField(
        'Количество людей на фотографии',
        max_length=50,
        blank=True,
        null=True
    )

    class Meta:
        """ добавляем порядок сортировки изображений """
        ordering = ['created']

    def __str__(self):
        """ возвращает строковое значение для представления объекта модели """
        return self.coordinates

    def get_absolute_url(self):
        """ возвращает ссылку на изображение """
        return reverse('images:image_detail', args=[self.id])
    class Image(models.Model):
        name = models.IntegerField()
        exif = ExifField(**kwargs)

        class Meta:
            # Model gets registered on every call
            # hence we need to change the `app_label` to avoid a warning...
            app_label = f'exiffield-{error}'
    class Image(models.Model):
        image = models.ImageField()
        camera = models.CharField(max_length=100)
        datetaken = models.DateTimeField(editable=False)
        exif = ExifField(source='image', denormalized_fields=denormalized_fields)

        class Meta:
            # Model gets registered on every call
            # hence we need to change the `app_label` to avoid a warning...
            app_label = f'exiffield-{error}'
Exemple #4
0
class Image(models.Model):
    image = models.ImageField()
    camera = models.CharField(
        editable=False,
        max_length=100,
    )
    exif = ExifField(
        source='image',
        denormalized_fields={'camera': exifgetter('Model')},
    )

    class Meta:
        app_label = 'tests'
Exemple #5
0
class UploadedImage(models.Model):
    objects = None
    image = models.ImageField(upload_to="media", blank=True)
    camera = models.CharField(
        editable=False,
        max_length=100,
    )
    exif = ExifField(
        source='image',
        denormalized_fields={
            'camera': exifgetter('Model'),
        },
    )
class EntryImage(AbstractImage):
    competition = models.ForeignKey(Competition,
                                    on_delete=models.CASCADE,
                                    related_name='entries',
                                    null=True)
    title = models.CharField(max_length=256)
    gear = models.CharField(max_length=256)
    location = models.CharField(max_length=256)
    submitted = models.DateTimeField(auto_now_add=True)
    user = models.ForeignKey(EntryUser,
                             on_delete=models.CASCADE,
                             related_name='entries',
                             null=True)
    vote_count = models.PositiveIntegerField(default=0)

    taken = models.DateTimeField(blank=True, null=True, editable=False)
    exif = ExifField(
        source='file',
        denormalized_fields={
            'taken': get_datetaken,
        },
    )

    @property
    def my_vote_count(self):
        return self.image_votes.count()

    def get_my_path(self):
        return Path('competition') / "{}".format(self.competition.id)

    def get_upload_to(instance, filename):
        ext = filename.split('.')[-1]
        x = EntryImage.objects.all().count() + 1
        p = instance.get_my_path()

        f = p / "{}-{}.{}".format(x, slugify(instance.title), ext)
        while f.is_file():
            x += 1
            f = p / "{}-{}.{}".format(x, slugify(instance.title), ext)
        return "{}".format(f)

    @property
    def points(self):
        return self.votes.aggregate(Sum('points'))['points__sum']

    @property
    def link(self):
        p = self.get_my_path() / self.filename
        return "{}/{}".format("/media", p)
Exemple #7
0
class ImageModel(models.Model):
    title = models.CharField(max_length=50, verbose_name='название фото')
    manufacturer = models.CharField(max_length=50,
                                    verbose_name='производитель')
    camera_model = models.CharField(max_length=50,
                                    verbose_name='модель камеры')
    file_url = models.ImageField(upload_to='images/%y/%m/%d/',
                                 verbose_name='файл')
    hash_of_file = models.CharField(
        max_length=255,
        editable=False,
    )
    exif = ExifField(source='file_url', )
    thumbnail = ImageSpecField(
        source='file_url',
        processors=[ResizeToFill(100, 100)],
        format='JPEG',
        options={'quality': 60},
    )
    file_size = models.CharField(max_length=50, verbose_name='размер файла')
    object_created = models.DateTimeField(auto_now_add=True,
                                          verbose_name='дата загрузки')
    photo_created = models.CharField(max_length=50,
                                     verbose_name='дата создания')

    def __str__(self):
        return self.title or ""

    @property
    def filesize(self):
        x = self.file_url.size
        y = 512000
        if x < y:
            value = round(x / 1000, 2)
            ext = ' kb'
        elif x < y * 1000:
            value = round(x / 1000000, 2)
            ext = ' Mb'
        else:
            value = round(x / 1000000000, 2)
            ext = ' Gb'
        return str(value) + ext

    class Meta:
        ordering = ['-object_created']
        verbose_name = "Фото"
        verbose_name_plural = "Фотки"
Exemple #8
0
class Photo(models.Model):
    album = models.ForeignKey(Album, on_delete=models.CASCADE)
    order = models.PositiveIntegerField(default=0, blank=False, null=False)
    pub_date = models.DateTimeField(default=timezone.now)
    photo_full = models.ImageField(upload_to='photos')
    photo_thumb = ImageSpecField(
        source='photo_full',
        processors=[ResizeToFill(width=400, height=267, upscale=False)],
        format='JPEG',
        options={'quality': 80})
    photo_mini_thumb = ImageSpecField(
        source='photo_full',
        processors=[ResizeToFit(width=200, upscale=False)],
        format='JPEG',
        options={'quality': 80})
    photo_large = ImageSpecField(
        source='photo_full',
        processors=[ResizeToFit(width=2048, upscale=False)],
        format='JPEG',
        options={'quality': 80})
    portfolio_bool = models.BooleanField(default=False)
    frontpage_bool = models.BooleanField(default=False)
    exif = ExifField(source='photo_full', )

    class Meta:
        verbose_name_plural = "Photos"
        ordering = ['order']

    def __str__(self):
        return self.photo_full.name

    def save(self, *args, **kwargs):
        super().save(*args, **kwargs)
        if self.portfolio_bool and not Portfolio.objects.filter(image=self):
            Portfolio.objects.create(image=self)
        elif Portfolio.objects.filter(image=self) and not self.portfolio_bool:
            Portfolio.objects.filter(image=self).delete()

        if self.frontpage_bool and not Frontpage.objects.filter(image=self):
            Frontpage.objects.create(image=self)
        elif Frontpage.objects.filter(image=self) and not self.frontpage_bool:
            Frontpage.objects.filter(image=self).delete()
Exemple #9
0
class Image(models.Model):
    title = models.CharField(max_length=254)
    image = CustomImageField(upload_to='user_img')

    image_thumbnail = ImageSpecField(source='image',
                                      processors=[ResizeToFill(350, 350)],
                                      format='JPEG',
                                      options={'quality': 80})

    exif = ExifField(
        source='image',
    )

    checksums = models.CharField(max_length=256, unique=True)

    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f'{self.title}'

    def get_absolute_url(self):
        return reverse('image-detail', kwargs={'pk': self.pk})
    class Image(models.Model):
        image = models.ImageField()
        exif = ExifField(source='image')

        class Meta:
            app_label = 'exiffield-exiftool'