I just upgraded my app to 1.7 (actually still trying).
This is what i had in models.py:
def path_and_rename(path):
def wrapper(instance, filenam
You can create function with kwargs like this:
def upload_image_location(instance, filename, thumbnail=False):
name, ext = os.path.splitext(filename)
path = f'news/{instance.slug}{f"_thumbnail" if thumbnail else ""}{ext}'
n = 1
while os.path.exists(path):
path = f'news/{instance.slug}-{n}{ext}'
n += 1
return path
and use this method with functools.partial in your model:
image = models.ImageField(
upload_to=upload_image_location,
width_field='image_width',
height_field='image_height'
)
thumbnail_image = models.ImageField(upload_to=partial(upload_image_location, thumbnail=True), blank=True)
You will get migration like this:
class Migration(migrations.Migration):
dependencies = [
('news', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='news',
name='thumbnail_image',
field=models.ImageField(blank=True, upload_to=functools.partial(news.models.upload_image_location, *(), **{'thumbnail': True})),
),
migrations.AlterField(
model_name='news',
name='image',
field=models.ImageField(height_field='image_height', upload_to=news.models.upload_image_location, width_field='image_width'),
),
]