name images with uuid instead of recipe ids

in order to stil be able to manually map images to recipes the name consists of uuid_recipeId.png
This commit is contained in:
vabene1111 2020-06-03 22:09:07 +02:00
parent 0684c47e2a
commit 9179bde8f9

View File

@ -1,4 +1,5 @@
import os import os
import uuid
from io import BytesIO from io import BytesIO
import simplejson import simplejson
@ -71,7 +72,7 @@ def internal_recipe_update(request, pk):
im_io = BytesIO() im_io = BytesIO()
img.save(im_io, 'PNG', quality=70) img.save(im_io, 'PNG', quality=70)
recipe.image = File(im_io, name=(str(recipe.pk) + '.png')) recipe.image = File(im_io, name=f'{uuid.uuid4()}_{recipe.pk}.png')
elif 'image' in form.changed_data and form.cleaned_data['image'] is False: elif 'image' in form.changed_data and form.cleaned_data['image'] is False:
recipe.image = None recipe.image = None