So im using a django formset to show multiple instances of a model and i have a file field in this model. the problem is when i add a file and save it, it’s not being shown in frontend part. this is the form:
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = (
"name",
"description",
"related_file"
)
widgets = {
'description': forms.Textarea(attrs={'rows':4, 'cols':10}),
}
the formset:
ProductFormSet = formset_factory(ProductForm)
and view:
class ProductView(LoginRequiredMixin, TemplateView):
template_name = 'pages/account/products.html'
success_url = reverse_lazy('account:products')
page_name = 'products'
page_title = _('Products')
crumb = _('Products')
def render_to_response(self, context: Dict[str, Any], **response_kwargs: Any):
formset = ProductFormSet(
initial=self.request.user.company.products.all().values())
context['formset'] = formset
return super().render_to_response(context, **response_kwargs)
to test i used these tags in my html file:
{{formset.0.initial}}
{{formset}}
and this is the result:
as you can see the initial data is there, and also filled other inputs correctly, but it did not fill the filefield data.