5

I've got an array of values from a checklist:

{% for groups in groupList %}
    <tr>
        <td id="checkboxes">
            <input type="checkbox" name="check" id="check_{{groups.GroupID}}">
        </td>
    <tr>
{% endfor %}

note this is just a snippet of a larger table. this is the relevant data though.

I need to take all checked items in the table and extract the groups.GroupID into an array and pass this to somewhere (presumably a view) where I can use the data to edit a model instance.

I know how to get the data to an array just fine, but I'm not sure how to approach passing the data on. Possibly a form but I'm not sure how I would implement this to be attached to a view and also pass an array.

1 Answer 1

5

Use request.POST.getlist:

eg:

for array_obj in request.POST.getlist('check'):
    # code

refer this

Sign up to request clarification or add additional context in comments.

2 Comments

This looks like what I need! Do you know how I would include an array in my post request?
I haven't been able to test it yet as I'm not sure how to include the array in my post request

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.