File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -674,4 +674,38 @@ https://github.com/django/django/blob/master/django/forms/widgets.py
674
674
The widget templates are in:
675
675
django/contrib/admin/templates/admin/widgets/
676
676
677
+ ```
678
+ settings.py:
679
+
680
+ INSTALLED_APPS = [
681
+ ...
682
+ 'django.forms',
683
+ ...
684
+ ]
685
+
686
+ FORM_RENDERER = 'django.forms.renderers.TemplatesSetting'
687
+
688
+
689
+ myapp/widgets.py:
690
+
691
+ from django import forms
692
+
693
+ class MyCustomWidget(forms.widgets.ClearableFileInput):
694
+ template_name = 'widgets/my_custom_widget.html'
695
+
696
+
697
+ myapp/forms.py:
698
+
699
+ class MyModelForm(forms.ModelForm):
700
+ class Meta:
701
+ model = MyModel
702
+ widgets = {
703
+ 'file': widgets.MyCustomWidget,
704
+ }
705
+ ```
706
+
707
+ Create template folder and template:
708
+
709
+ ` myapp/templates/widgets/my_custom_widget.html `
710
+
677
711
You can’t perform that action at this time.
0 commit comments