Update picture upload

This commit is contained in:
Michael Götz 2018-01-12 23:24:27 +01:00
parent bdc6d36ce4
commit a93859167a

View File

@ -10,7 +10,7 @@ from django.contrib.auth.models import User
from django.core.files.uploadedfile import SimpleUploadedFile from django.core.files.uploadedfile import SimpleUploadedFile
from django.db import models from django.db import models
from django.utils import timezone from django.utils import timezone
from django.utils.encoding import smart_text from django.utils.encoding import smart_str
from enum import Enum from enum import Enum
MAX_LENGTH = 256 MAX_LENGTH = 256
@ -114,7 +114,7 @@ class UserFoodImage(models.Model):
suf = SimpleUploadedFile(os.path.split(self.image.name)[-1], suf = SimpleUploadedFile(os.path.split(self.image.name)[-1],
temp_handle.read(), temp_handle.read(),
content_type='image/jpg') content_type='image/jpg')
str_food = smart_text(self.food.name, encoding='utf-8') str_food = smart_str(self.food.name, encoding='utf-8')
self.thumb.save('%s_%s_thumbnail.%s' % (str_food, self.user.username, 'jpg'), suf, save=False) self.thumb.save('%s_%s_thumbnail.%s' % (str_food, self.user.username, 'jpg'), suf, save=False)
# save the image object # save the image object
self.image.name = "%s_%s_original.%s" % (str_food, self.user.username, 'jpg') self.image.name = "%s_%s_original.%s" % (str_food, self.user.username, 'jpg')