I am trying to create a page with formset in it. So far I've gotten the following:
forms.py
class ContractorForm(forms.ModelForm):
class Meta:
model = Contractor
fields = [
'first_name', 'last_name', 'email', 'company_name',
]
views.py
class ContractorUpdateView(SimpleLoginRequiredMixin, TemplateView):
def get(self, request, *args, **kwargs):
"""Handle GET requests: instantiate a blank version of the form."""
ContractorFormSet = formset_factory(
Contractor)
contractor_formset = ContractorFormSet()
context = {"contractor_formset": contractor_formset}
return render(
request, "accounts/contractor_form.html", context)
contractor_form.html
<div class="card-body">
<form class="" method="post" action="" id="facility_contractor_form">
{% for form in contractor_formset %}
{% csrf_token %}
{{ form.as_p }}
{% endfor %}
</form>
</div>
<!-- /.card-body -->
<div class="card-footer">
<a href="javascript:history.back()" class="btn btn-secondary">Cancel</a>
<input type="submit" form="facility_contractor_form" value="Save Changes"
class="btn btn-success float-right">
</div>
But when I try to open the page, I'll get the following error:
TypeError at /facility/2/contractor/
Contractor() got an unexpected keyword argument 'auto_id'
Any ideas? I think my using for
maybe the wrong idea
Your ContractorUpdateView references the model, while it should reference the form, so it gotta be: