作业设置表单在view.py中保存更改时重置active / deactive属性

时间:2018-05-06 22:13:25

标签: python django

我为我的工作页面编写了一个主动/非主动功能。当用户更改作业的某些属性并保存更改时,活动/非活动功能将重新设置为非活动状态。以下是我的job_settings和active / deactive函数:

views.py:

@login_required
@user_is_type('communitypartner')
def job_settings(request,job_id):
    job = Job.objects.get(id=job_id)

    #if the request was a GET
    if request.method == 'GET':
        form = JobEditForm(instance=job)

    elif request.method == 'POST':
        form = JobEditForm(request.POST, instance=job)

        #check form validity
        if form.is_valid() :
            #get form info
            job = form.save(request)
            #job = form.save()
            #add new orgs/remove removed orgs here

            message = "Job {0} has been modified.".format(job.name)
            messages.add_message(request, messages.INFO, message)

        return render(request, 'main/job_settings.html', {'form':form,'job' : job})

@login_required
def job_status_update(request):
    status = request.GET['status']
    job_id = request.GET['Jobid'] 
    if status == 'Active':
        flag = True
    else:
        flag = False
    job = Job.objects.get(pk=job_id)
    try:
        #job = Job.objects.get(pk=job_id)
        job.active = flag
        job.save()
        #write back
        return HttpResponse(status)
    except Exception as e:
        return JsonResponse(status)

我需要帮助解决此问题并维护活动/非活动功能的原始状态

1 个答案:

答案 0 :(得分:0)

找到解决方案。我需要在设置表单中添加active / deactive功能。这样,当重新渲染所有属性时,不会遗漏此特征并将其设置回原始特征。