Skip to main content
Editando el cuerpo de la problemática para mejor visualización del tema.
Origen Enlace

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

Tengo dos modelos con relación ManyToMany y quiero insertar integrantes pero al intentarlo me genera un error.

Lo que quiero lograr es crear un integrante nuevo que es almacenado en el modelo Member.
Lo que hago es tomar el pk desde la tabla que es mostrada y lo asigno a la variable pk para tener el proyecto, al final recojo todos los valores del formulario y creo un nuevo integrante, después lo que hago es salvar el integrante y le paso el pk al proyecto que se asigna, en ese momento me dice:

UnboundLocalError: local variable 'data' reference before assignment.

Mi código es el siguiente:

Y el Error es el siguiente:

response = wrapped_callback(request, *callback_args,
**callback_kwargs **callback_kwargs) File "C:\Users\Edivaldo Gomes\PycharmProjects\science\applications\projects\views.py", line 423 423, in ajax_create_other_member return JsonResponse(data) UnboundLocalError UnboundLocalError: local variable 'data' referenced before assignment [2019 [2019/01/25 14:00:15] HTTP POST /ciencia/project/member/other/add 500 [0 [0.19, 127.0.0.1:56663]

Alguien sabe qué estoy haciendo mal.
Espero puedan ayudarme.

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

Error :

response = wrapped_callback(request, *callback_args,
**callback_kwargs) File "C:\Users\Edivaldo Gomes\PycharmProjects\science\applications\projects\views.py", line 423, in ajax_create_other_member return JsonResponse(data) UnboundLocalError: local variable 'data' referenced before assignment [2019/01/25 14:00:15] HTTP POST /ciencia/project/member/other/add 500 [0.19, 127.0.0.1:56663]

error en modelo ManyToMany

Tengo dos modelos con relación ManyToMany y quiero insertar integrantes pero al intentarlo me genera un error.

Lo que quiero lograr es crear un integrante nuevo que es almacenado en el modelo Member.
Lo que hago es tomar el pk desde la tabla que es mostrada y lo asigno a la variable pk para tener el proyecto, al final recojo todos los valores del formulario y creo un nuevo integrante, después lo que hago es salvar el integrante y le paso el pk al proyecto que se asigna, en ese momento me dice:

UnboundLocalError: local variable 'data' reference before assignment.

Mi código es el siguiente:

Y el Error es el siguiente:

response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\Edivaldo Gomes\PycharmProjects\science\applications\projects\views.py", line 423, in ajax_create_other_member return JsonResponse(data) UnboundLocalError: local variable 'data' referenced before assignment [2019/01/25 14:00:15] HTTP POST /ciencia/project/member/other/add 500 [0.19, 127.0.0.1:56663]

Alguien sabe qué estoy haciendo mal.
Espero puedan ayudarme.

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)

Error :

response = wrapped_callback(request, *callback_args,
**callback_kwargs) File "C:\Users\Edivaldo Gomes\PycharmProjects\science\applications\projects\views.py", line 423, in ajax_create_other_member return JsonResponse(data) UnboundLocalError: local variable 'data' referenced before assignment [2019/01/25 14:00:15] HTTP POST /ciencia/project/member/other/add 500 [0.19, 127.0.0.1:56663]

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)
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)

Error :

response = wrapped_callback(request, *callback_args,
**callback_kwargs) File "C:\Users\Edivaldo Gomes\PycharmProjects\science\applications\projects\views.py", line 423, in ajax_create_other_member return JsonResponse(data) UnboundLocalError: local variable 'data' referenced before assignment [2019/01/25 14:00:15] HTTP POST /ciencia/project/member/other/add 500 [0.19, 127.0.0.1:56663]

Tengo dos modelos y que tiene relacion ManyToMany quiero insertar integranntes -> UnboundLocalError: local variable 'data' referenced before assignmentintegrantes 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)

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)

Tengo dos modelos tiene relacion ManyToMany quiero insertar integranntes -> UnboundLocalError: local variable 'data' referenced before assignment

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)

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)
Origen Enlace
Loading