我动态创建了一个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() argument must be a string or a number, not 'QueryDict'和Form error int() argument must be a string or a number, not 'QueryDict',但仍然没有得到它。
答案 0 :(得分:1)
您正在将request.POST查询字典传递给:
OptionalItems.objects.filter(item=item)
也许你打算传递一些像request.POST ['item_id']的内容?