INPUT TEXT in grid

32 views
Skip to first unread message

Gabriel Araya Garcia

unread,
Sep 28, 2021, 5:14:30 PM9/28/21
to Django users
I have one grid

<form name="form" method="POST">
       </div>
                    {% for pr in parasalida %}
                          <tr style="font-size:14px">
                            <td>{{ pr.estado}}</td>
                            <td>{{ pr.fecha_ing|date:'d-m-Y'}}</td>
                            <td>{{ pr.lote}}</td>
                            <td>{{ pr.oc_ascoex}}</td>
                            <td>{{ pr.cantidad}}</td>
                            <td>{{ pr.extraida}}</td>
                            <td><input type="number" name='{{pr.id_reg}}' class='saca' value="{{saca_x}}" placeholder='0'/></td>

                          </tr>
                    {% endfor %}

but, I don't know how to get the value in view:

    parasalida = Parasalida.objects.all() 
    a_prueba = []
    for cur in parasalida:
        saca_x = request.GET.get('cur.id_reg') #  template's value according to name property
        a_prueba.append(saca_x)

The list is full with  [None,None,None,..]

All others fields are already with values. The only values that user input is "input text"

Thank for your help

David Nugent

unread,
Sep 28, 2021, 7:38:30 PM9/28/21
to django...@googlegroups.com
Request.GET can't apply when processing a POST request.

You are quoting 'cur.id_reg' when accessing the GET (should be POST) params and it probably should not be - you need to access the "name" attribute that your form uses. You should also be using cleaned_data after using proper form validation, and in this case you should probably be using a formset instead of manually generating a multiple record input form.

HTH, David

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a2ba10d5-639e-4a08-88fe-a4206e18c249n%40googlegroups.com.

Adeyemi Deji

unread,
Sep 29, 2021, 3:58:11 PM9/29/21
to django...@googlegroups.com
Based on my observation. Your form doesn't have it's href attribute, secondly in the view, the function should ve a post method and not get, thirdly back to the template, u should have a name attribute for ur input tag which u do but the value should be an arbitrary name or any name of ur choice as a string which u will use to reference in the view function.

Little modification to ur view function:
To reference the input name attribute lets give it a value called para.

def parasalidaView(request):
        if request.method == 'POST'
                parasalida = Parasalida.objects.all()
                a_prueba = []
                for cue in parasalida:
                        data = request.POST.get('para')
                        a_prueba.append(data)
                


Gabriel Araya Garcia

unread,
Oct 2, 2021, 8:44:30 PM10/2/21
to Django users
Thanks for your help, My problem I've solved. David Nugent says that the template must be built with using 'POST', and also the grid (table) is from database table, then the name  in each row I put the ID (numeric), therefore in view get the value with: 
valor_saca = request.POST.get(str(sigma.id_reg)) # obligadamente debe ser string
Here is important the 'str', it must be string (chracter, or no numeric)

(Excuse me my english )
Regards      

Adeyemi Deji

unread,
Oct 3, 2021, 4:35:48 PM10/3/21
to django...@googlegroups.com
Good to know that you now understand why ur code wasn't working and you have learnt from asking questions. We always here for you. Peace

Reply all
Reply to author
Forward
0 new messages