How to get a value of a multiple of multiple select?

Dear All,

I have a multiple of multiple select like this.

HTML Code that I want to achieve the result:

<tr id="activity_row-1">
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="activity" id="activity-1"></select>
        </td>
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="sub_activity" id="sub_activity-1"></select>
        </td>
        <td style="width:5%" class="action_col">
            <button type="button" class="btn btn-sm btn-icon btn-primary"
                    onclick="clone_row(this,'table#activiry')">
                <span class="btn-inner--icon"><i class="fas fa-plus"></i></span>
            </button>
        </td>
    </tr>
<tr id="activity_row-2">
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="activity" id="activity-2"></select>
        </td>
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="sub_activity" id="sub_activity-2"></select>
        </td>
        <td style="width:5%" class="action_col">
            <button type="button" class="btn btn-sm btn-icon btn-primary"
                    onclick="clone_row(this,'table#activiry')">
                <span class="btn-inner--icon"><i class="fas fa-plus"></i></span>
            </button>
        </td>
    </tr>

in the server side I got this value:

activity: ["activity1", "activity2"]
sub_activity: ["sub_activity1-1", "sub_activity1-2", "sub_activity2-1", "sub_activity2-2", "sub_activity2-3"] 

The activity value is no problem, I can get the value with request.POST.getlist('activity'). But for the sub_activity I want to get the value with this format.

"sub_activity": [
     ["sub_activity1-1", "sub_activity1-2"], 
     ["sub_activity2-1", "sub_activity2-2", "sub_activity2-3"]
]

I have trying to make the field name for sub_activity unique per row, like code below, but its more effort to approach the value above:

        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="activity" id="activity-1"></select>
        </td>
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="sub_activity_1" id="sub_activity-1"></select>
        </td>
        <td style="width:5%" class="action_col">
            <button type="button" class="btn btn-sm btn-icon btn-primary"
                    onclick="clone_row(this,'table#activiry')">
                <span class="btn-inner--icon"><i class="fas fa-plus"></i></span>
            </button>
        </td>
    </tr>
<tr id="activity_row-2">
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="activity" id="activity-2"></select>
        </td>
        <td style="width:30%">
            <select class="form-control form-control-sm" multiple
                    name="sub_activity_2" id="sub_activity-2"></select>
        </td>
        <td style="width:5%" class="action_col">
            <button type="button" class="btn btn-sm btn-icon btn-primary"
                    onclick="clone_row(this,'table#activiry')">
                <span class="btn-inner--icon"><i class="fas fa-plus"></i></span>
            </button>
        </td>
    </tr>

I just hoping there is more easier method to approach the value I want.

Thankyou All.

You’re on the right track - you need to ensure that each select field has a unique name. You can then do whatever processing you need to do with that field in the view, to collect that data however you wish.

Hi Ken,

Thank you for your response, I just wanted to make sure that was the only solution.

Thankyou very much.