[Fixed]-How do I set up a image upload to a folder that the folder name is a value of another field in the model in DJango

1👍

You need a custom upload handler.

def image_upload_handler(instance, filename):
    return 'RANKS/{genre}/{filename}'.format(
        genre=instance.genre,
        filename=filename
    )

class RankStructure(models.Model):
    image = models.ImageField(upload_to=image_upload_handler, blank=True)

Also I recommend using this for image fields: https://github.com/edoburu/django-any-imagefield

Leave a comment