我喜欢使用jquery
(即jquery.fancytree
)或bootstrap
库来重新渲染我的表单。我不知道怎么做!
我不想使用mptt_tags
recursetree
。我需要使用表单而不是模型。
Snapshot of the app with two level is shown.
forms.py
from django import forms
from mptt.forms import TreeNodeMultipleChoiceField
class RSMDriveForm(forms.Form):
choices = TreeNodeMultipleChoiceField(queryset=RSMDriveModel.objects.all(),
required=False,
level_indicator=mark_safe(" "),
label="",
widget=forms.widgets.SelectMultiple(),
)
def __init__(self, *args, **kwargs):
super(RSMDriveForm, self).__init__(*args, **kwargs)
views.py
def rsmgui_home(request):
form = RSMDriveForm()
context = {'drive_nodes': form }
return render(request, "rsmgui_nav.html", context)
rsmgui_nav.html
<form class="form-horizontal" role="form" id="drive-form" method="post" action="" >
{% csrf_token %}
{% for choice in drive_nodes.choices %}
{{ choice }}
{% endfor %}
</form>