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'},