I'm using easy-thumbnails, the original file is saved correctly but the thumbnails are being saved with a duplicate file extension:
11.jpg
11.jpg.100x100_q85.jpg
I would like the thumbnails to be named like this:
11.100x100_q85.jpg
My model looks like this:
def image_filename(instance, filename):
folder = 'posts/image'
_, ext = os.path.splitext(filename)
new_name = str(instance.id) + ext
return os.path.join(folder, new_name)
class Post(models.Model):
name = models.CharField(max_length=255, unique=True)
image = ThumbnailerImageField(upload_to=image_filename, null=True, blank=True)
Since im using Django Rest Framework I created a serializer following this post: Django easy-thumbnails serialize with Django Rest Framework
class ThumbnailSerializer(serializers.ImageField):
def __init__(self, alias, *args, **kwargs):
super().__init__(*args, **kwargs)
self.read_only = True
self.alias = alias
def to_representation(self, value):
if not value:
return None
url = thumbnail_url(value, self.alias)
request = self.context.get('request', None)
if request is not None:
return request.build_absolute_uri(url)
return url
Does anyone know how I can get the correct naming on my thumbnails?
Thanks!