1
의 양식 필드를 렌더링합니다.장고 수동으로 내가 관련된 모델의 기록을 저장하는 <code>inlineformset</code>와 <code>CreateView</code>을 대신 form.as_p
class BusinessForm(ModelForm):
class Meta:
model = Business
exclude =()
BusinessAddressFormSet = inlineformset_factory(
Business,
BusinessAddress,
form=BusinessForm,
extra=1,
can_delete=False
)
과 business_form.html
에, 내가 뭘
forms.py
이것은 위의 필드는
- line_1
- line_2
- city
- state
- postal
같은 주소 모델의 모든 필드를 렌더링
<form method="post">
{% csrf_token %}
// render business form
{{ form.as_p }}
// render business address fields
{{ business_address.management_form }}
<table class="table">
{{ business_address.management_form }}
{% for form in business_address.forms %}
{% if forloop.first %}
<thead>
<tr>
{% for field in form.visible_fields %}
<th>{{ field.label|capfirst }}</th>
{% endfor %}
</tr>
</thead>
{% endif %}
<tr class="{% cycle 'row1' 'row2' %} formset_row">
{% for field in form.visible_fields %}
<td>
{# Include the hidden fields in the form #}
{% if forloop.first %}
{% for hidden in form.hidden_fields %}
{{ hidden }}
{% endfor %}
{% endif %}
{{ field.errors.as_ul }}
{{ field }}
</td>
{% endfor %}
</tr>
{% endfor %}
</table>
입니다에서 렌더링 됨. 이후, 나는 다른 필드에 대한 인라인 양식 아이콘과 함께 사용할 별도의 HTML 템플릿이 있습니다.
오류 필드 및 숨겨진 필드와 함께 business_address
의 필드를 수동으로 렌더링하는 방법은 무엇입니까?
에서보기를 할 수 있습니다. 'business_address' 필드의 필드를 렌더링하는 방법은? 이것은 inlineformset이기 때문에. –
'business_address.line_1.label'을 시도했지만 아무 것도 출력하지 않았습니다. –
'{{business_address.form.line_1.label}}' –