From 9179bde8f9a8a547b44b183f993051fd77613263 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Wed, 3 Jun 2020 22:09:07 +0200 Subject: [PATCH] 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 --- cookbook/views/edit.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cookbook/views/edit.py b/cookbook/views/edit.py index 95b032296..4dda8c653 100644 --- a/cookbook/views/edit.py +++ b/cookbook/views/edit.py @@ -1,4 +1,5 @@ import os +import uuid from io import BytesIO import simplejson @@ -71,7 +72,7 @@ def internal_recipe_update(request, pk): im_io = BytesIO() 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: recipe.image = None