我已经动态地创建了一个 django 表单来实现一些像这样的自定义行为,
def partial_order_item_form(item):
"""dynamic form limiting optional_items to their items"""
class PartialOrderItemform(forms.Form):
quantity = forms.IntegerField(widget=forms.TextInput(attrs={'size':'2', 'class':'quantity','maxlength':'5'}))
option = forms.ModelMultipleChoiceField(queryset=OptionalItems.objects.filter(item=item),widget= forms.RadioSelect())
return PartialOrderItemform
我继续验证我的观点,
def show_item(request,id):
a = Item.objects.get(pk=id)
if request.method == 'POST':
form = partial_order_item_form(request.POST)
if form.is_valid():
order.add_to_order(request,a)
else:
form = partial_order_item_form(item=id)
context={
'form':form,
}
return render_to_response('item.html',context,context_instance=RequestContext(request))
当我提交表格时,我收到int() argument must be a string or number not 'querydict'
错误。
我看过int() 参数必须是字符串或数字,而不是 'QueryDict'和Form 错误 int() 参数必须是字符串或数字,而不是 'QueryDict'但仍然没有得到它。