[Answered ]-Python loop until length

1👍

You can enumerate over the items with a range(…) [Python-doc]:

def submit_quality_dept_application(request, application_id):
    n = int(request.data['length'])
    application = Application.objects.get(id=application_id)
    application_state = application.application_state
    for i in range(n):
        doc = request.FILES[f'doc{i}']
        application_state[f'doc{i}'] = doc.name
    Application.objects.filter(id=application_id).update(application_state=application_state)
    return Response(length, status=status.HTTP_200_OK)

But I’m not sure if the is the best way to handle multiple files. It might be better to submit a list of files as request, for example for the same key.

Leave a comment