gpt4 book ai didi

django - int() 参数必须是字符串或数字,而不是 'QueryDict'

转载 作者:行者123 更新时间:2023-12-02 08:47:18 26 4
gpt4 key购买 nike

我正在表单上呈现 3 个多个选择框。我正在过滤每个盒子以拥有单独的一天类型。当我提交表单时,出现此错误。

int() argument must be a string or a number, not 'QueryDict'

我必须做什么才能保存我的表单?

这就是我在 forms.py 文件上所做的事情,以获得每个选择框的不同过滤。

class ContractForm(forms.ModelForm):

def __init__(self, project_id, *args, **kwargs):
super(ContractForm, self).__init__(*args, **kwargs)
self.fields['shoot_day'].queryset = Day.objects.filter(type=SHOOT, project__id=project_id)
self.fields['travel_day'].queryset = Day.objects.filter(type=TRAVEL, project__id=project_id)
self.fields['additional_day'].queryset = Day.objects.filter(type=ADDITIONAL, project__id=project_id)
<小时/>

我像这样获取我的project_id:

def editcontract(request, contract_id, slug):
context_dict = {}
contract = get_object_or_404(Contract, pk=contract_id)
if request.method == 'POST':
form = ContractForm(request.POST, instance=contract)
if form.is_valid():
form.save()
TvUsageForm = TvUsageFormSet(request.POST, instance=contract)
AdditionalMediaUsageForm = AdditionalMediaUsageFormSet(request.POST, instance=contract)
TvUsageForm.save()
AdditionalMediaUsageForm.save()
return HttpResponseRedirect(reverse('contract_list', kwargs={'slug':slug}))
else:
form = ContractForm(instance=contract, project_id=contract.project_id)
TvUsageForm = TvUsageFormSet(instance=contract)
AdditionalMediaUsageForm = AdditionalMediaUsageFormSet(instance=contract)
project = get_object_or_404(Project, slug=slug)
context_dict = { 'form': form,
'tvusage_form':TvUsageForm,
'additional_form':AdditionalMediaUsageForm,
'project':project
}
return render_to_response('contracts/edit_contract.html', context_dict, RequestContext(request))

最佳答案

您对参数列表和关键字参数感到困惑:

而不是:

ContractForm(instance=contract, project_id=contract.project_id)

你想要:

ContractForm(contract.project_id, instance=contract)

详细说明:您的构造函数接受项目 id 作为第一个参数,而不是关键字参数。因此,您需要将其作为第一个参数。简单的困惑,嗯?

关于django - int() 参数必须是字符串或数字,而不是 'QueryDict',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6649499/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com