Hello
I am using a ListView to display and select forms within a formset.
The code for the get is the following
def get_initial(self):
"""create a list of initial values for each element of the object_list"""
initial = [bmf.StitchTechniqueRepresentation(mst_pk, self.member).to_dict() for mst_pk in self.pks]
return initial
def get_queryset(self):
return self.formset.forms
def get(self, request, *args, **kwargs):
form_class = self.form_class
self.formset = form_class(**self.get_form_kwargs())
#all_names = MachineSTMixin.all_names(self.member)
#setattr(self.formset, 'all_names', all_names)
return super().get(self.request, *args, **kwargs)
def get_form_kwargs(self):
kwargs = {'initial': self.get_initial()}
if self.request.method in ('POST', 'PUT'):
kwargs.update({
'data': self.request.POST,
'files': self.request.FILES,
})
return kwargs
In the template I have
<form method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="container px-0">
<div class="d-flex flex-column gap-3">
{% for form in object_list %}
{% include "app_fabric/_st_row_form.html" with form=form actions_json='[{"label":"display SFD","href":"/app_fabric/displaySFD/{id}"},{"label":"edit ST","href":"/app_fabric/editST/{id}"}]'%}
{% empty %}
<div class="alert alert-light border mb-0">{% translate "No results." %}</div>
{% endfor %}
</div>
I neef to access fields of the form individually in the template and variables such as {{form.fieldname}} seems to be empty.
In my IDE I get builtins.AttributeError MySTForm has no attribute field name.
MySTForm is the class of the form in the formset.
an someone tell me why?