Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django Formset-保存前更新Views.py中的值_Python_Django_Formset - Fatal编程技术网

Python Django Formset-保存前更新Views.py中的值

Python Django Formset-保存前更新Views.py中的值,python,django,formset,Python,Django,Formset,我试图将表单集中每个表单上的值设置为单个值。 我不知道如何才能做到这一点。。。views.py函数如下: 比如: formset.idcst\u cnt=id views.py def customer_contacts(request, id): ContactFormSet = modelformset_factory(AppContactCnt, can_delete=True, fields=( 'name_cnt', 'phone_cnt', 'email_cn

我试图将表单集中每个表单上的值设置为单个值。 我不知道如何才能做到这一点。。。views.py函数如下:

比如:
formset.idcst\u cnt=id

views.py

def customer_contacts(request, id):
    ContactFormSet = modelformset_factory(AppContactCnt, can_delete=True, fields=(
        'name_cnt', 'phone_cnt', 'email_cnt', 'note_cnt', 'receives_emails_cnt'), max_num=3, extra=3)
    formset = ContactFormSet(queryset=AppContactCnt.objects.filter(idcst_cnt=id), prefix='contact')
    if request.method == 'GET':
        context = {'formset': formset}
        return render(request, 'customer_contacts.html', context=context)
    if request.method == 'POST':
        formset = ContactFormSet(request.POST, prefix='contact')
        if formset.is_valid():
            print("we're updating contacts for " + str(id))
            # formset.save()

        return HttpResponseRedirect(request.META.get('HTTP_REFERER'))

if request.method==“POST”
下,您可以在
if request.method==“POST”
中对表单集的表单执行
,谢谢!真不敢相信我居然没想到,哼!!发生了:),我刚刚添加了答案。所以我知道这是不相关的,我可以提出一个新问题,但我现在遇到了这个错误:
无法分配“1930”:“AppContactCnt.idcst\u cnt”必须是“AppCustomerCst”实例。
有什么想法吗?它看起来像是而不是整数id
idcst\u cnt=id
,您需要将其分配给具有该id的AppCustomerCst实例,如下所示:
idcst\u cnt=AppCustomerCst.objects.get(id=id)