ImageField / FileField Django form Currently unable to trim the path to filename

前端 未结 1 2070
时光说笑
时光说笑 2021-01-24 08:20

I have a ImageField that stores in AWS S3 (similar to FileField). In the form, it has this \"Currently\" label that shows the image file path. I would like to trim and just show

相关标签:
1条回答
  • 2021-01-24 09:16

    In Django 1.11.x get_template_substitution_values is deprecated. New implementation of CustomClearableFileInput could be as follow:

    class CustomClearableFileInput(ClearableFileInput):
        def get_context(self, name, value, attrs):
            value.name = path.basename(value.name)
            context = super().get_context(name, value, attrs)       
            return context
    
    0 讨论(0)
提交回复
热议问题