From 045f18bd8381d01c92ee415b7896afe9d5487d03 Mon Sep 17 00:00:00 2001 From: reverend Date: Tue, 28 Jul 2020 09:39:11 +0200 Subject: [PATCH] Fixed lambda serialization error --- .../migrations/0005_auto_20200728_0738.py | 20 +++++++++++++++++++ source/lostplaces/lostplaces_app/models.py | 5 ++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 source/lostplaces/lostplaces_app/migrations/0005_auto_20200728_0738.py diff --git a/source/lostplaces/lostplaces_app/migrations/0005_auto_20200728_0738.py b/source/lostplaces/lostplaces_app/migrations/0005_auto_20200728_0738.py new file mode 100644 index 0000000..d0abd4a --- /dev/null +++ b/source/lostplaces/lostplaces_app/migrations/0005_auto_20200728_0738.py @@ -0,0 +1,20 @@ +# Generated by Django 3.0.8 on 2020-07-28 07:38 + +from django.db import migrations +import django_thumbs.fields +import lostplaces_app.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('lostplaces_app', '0004_auto_20200727_1803'), + ] + + operations = [ + migrations.AlterField( + model_name='placeimage', + name='filename', + field=django_thumbs.fields.ImageThumbsField(max_length=50, sizes=({'code': 'thumbnail', 'wxh': '390x390'}, {'code': 'hero', 'wxh': '700x700'}, {'code': 'large', 'wxh': '1920x1920'}), upload_to=lostplaces_app.models.generate_image_upload_path), + ), + ] diff --git a/source/lostplaces/lostplaces_app/models.py b/source/lostplaces/lostplaces_app/models.py index dc232c6..c807159 100644 --- a/source/lostplaces/lostplaces_app/models.py +++ b/source/lostplaces/lostplaces_app/models.py @@ -17,9 +17,12 @@ class Place (models.Model): def __str__(self): return self.name +def generate_image_upload_path(instance, filename): + return 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1] + class PlaceImage (models.Model): filename = ImageThumbsField( - upload_to=lambda instance, filename: 'places/' + str(uuid.uuid4())+'.'+filename.split('.')[-1], + upload_to=generate_image_upload_path, max_length=50, sizes = ( {'code': 'thumbnail', 'wxh': '390x390'},