Skip to content

Commit

Permalink
Make ImageFormField render with accept="image/*"' HTML attribute
Browse files Browse the repository at this point in the history
Since Django 2.1, the default forms.ImageField has rendered with
accept="image/*".  Copy the code here to do the same.
  • Loading branch information
tubaman committed May 7, 2023
1 parent 4e77896 commit 064902e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions sorl/thumbnail/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from django.db.models import Q
from django import forms
from django.utils.translation import gettext_lazy as _
from django.forms.widgets import FileInput

from sorl.thumbnail import default

Expand Down Expand Up @@ -68,3 +69,9 @@ def to_python(self, data):
f.seek(0)

return f

def widget_attrs(self, widget):
attrs = super().widget_attrs(widget)
if isinstance(widget, FileInput) and 'accept' not in widget.attrs:
attrs.setdefault('accept', 'image/*')
return attrs

0 comments on commit 064902e

Please sign in to comment.