0
你能告訴我如何將我的複選框值傳遞給服務器嗎?
views.py
[Django] [MultipleChoiceField]將複選框值傳遞給服務器
def viewtest(request):
if request.method == "POST":
form=testForm(request.POST)
if(form.is_valid():
form.save()
elif request.method == "GET":
form=testForm()
return render(request,"test/register.html",{"testform":form})
forms.py
class testForm(forms.ModelForm):
workday=forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple(), choices=workdayType)
class Meta:
model=test
fields=('name','tel')
register.html
<table>
<form method="post" action="{% url "viewtest" %}">
{{testform.as_table}}
</form>
<input type="submit" value="register"/>
</table>
但在服務器上,看不到多個數據。你能提供一些想法嗎?