[Answer]-Django cutom image name on upload

1👍

You can specify a function to return a custom path for the ImageField:

def get_upload_path(instance, filename):
    return 'your/custom/path/here'

class Link(models.Model):
    . . .
    link_image = models.ImageField(upload_to=get_upload_path)

Now you can use information from the model instance to build up the path to upload to.

Additionally, you don’t want to use the {% static %} template tag to specify the path to the image. You would just use the .url property of the field:

<img src="{{ link.link_image.url }}" alt="{{ link.link_description }}" />

Leave a comment