Skip to content

Commit 064902e

Browse files
committed
Make ImageFormField render with accept="image/*"' HTML attribute
Since Django 2.1, the default forms.ImageField has rendered with accept="image/*". Copy the code here to do the same.
1 parent 4e77896 commit 064902e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

sorl/thumbnail/fields.py

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.db.models import Q
33
from django import forms
44
from django.utils.translation import gettext_lazy as _
5+
from django.forms.widgets import FileInput
56

67
from sorl.thumbnail import default
78

@@ -68,3 +69,9 @@ def to_python(self, data):
6869
f.seek(0)
6970

7071
return f
72+
73+
def widget_attrs(self, widget):
74+
attrs = super().widget_attrs(widget)
75+
if isinstance(widget, FileInput) and 'accept' not in widget.attrs:
76+
attrs.setdefault('accept', 'image/*')
77+
return attrs

0 commit comments

Comments
 (0)