Skip to main content

Tengo dos modelos y que tiene relacion ManyToMany quiero insertar integrantes y por su vez me da este error

def ajax_create_member(request):
    member_form = MemberForm()
    pk = request.GET.get('pk')
    global e
    e.append(pk)
    if request.method == 'POST':
        name = request.POST['name']
        surnames = request.POST['surnames']
        category = request.POST['category']
        email = request.POST['email']
        CI = request.POST['CI']
        academic_year = request.POST['academic_year']
        form = MemberForm(request.POST, request.FILES)
        if form.is_valid():
            print('Este es el pk')
            print(e[0])
            project = Project.objects.get(pk=d[0])
            d = []
            member = Member.objects.create(
                name=name, surnames=surnames, category=category, email=email, CI=CI, academic_year=academic_year
            )
            project.member=member
            project.save()
            projects = Project.objects.all()
            data = {
                'msg': 'El integrante se ha guardado satisfactoriamente',
                'page': render_to_string('project/list_project.html', {'projects': projects}, request=request),
                'header': render_to_string('project/dinamic_project.html', request=request),
            }
            return JsonResponse(data)
    else:
        data = {
            'page': render_to_string('project/member/add.html', {'form': member_form}, request=request)
        }
    return JsonResponse(data)