django - Override FileField widget in InlineFormset_factory? -


I want to change the default upload field (FileField) in an inlineformset_factory form, to use AdminFileWidget from django.contrib . Admin.widgets Its purpose is to show the path of the currently uploaded file, as in the form of administration (perhaps any other way to do this?).

I have no problem in working the widgets using custom form, just do not understand how to change the widget in inlineformset_native.

This will get you the Admin FileField widget instead of a standard file with 5 additional fields.

views.py

  MySpecialFormset = inlineformset_factory (MyParentModel, MyChildModel, form = MyChildModelForm, additional = 5) formset = MySpecialFormset (example = myparentmodelinstance) #add request.POST and request. If FILES are used on post circuit then import django.contrib.admin.widgets from  
  AdminFileWidget class MyChildModelForm (forms.ModelForm): Square Meta: Model = MyChildModel def __init __ (self, * args, ** kwargs): super (MyChildModelForm, self) .__ init __ (* args, ** kwargs) self.fields ['my_file_field']. Widget = AdminFileWidget ()  

Comments