django-file-resubmit icon indicating copy to clipboard operation
django-file-resubmit copied to clipboard

Fix input: rendering ClearableFileInput (django 4.2)

Open corentinbettiol opened this issue 1 year ago • 1 comments

Starting with django 4.2 we can't see the file anymore on the error page, because a fix was implemented for an eleven years old ticket and it broke the FileField bound_data function, who's called when rendering the widget.

So here's our fix (found this after a wild ride, you just need to redefine the function and to return the right data):

class FixedClearableFileInput(forms.FileField):
    def bound_data(self, data, initial):
        return data

# ...

class OurSuperForm(SomeOtherForm):
    logo = FixedClearableFileInput()

corentinbettiol avatar Feb 06 '24 16:02 corentinbettiol