Manipulate multiple forms generated with an input value in Django

I want to manipulate mltiple forms according to an input value. I use the code below to generate a number of forms :

$(function() {
            var input = $('<div><br><table class="form-table">\
              <tr>\
                <td><label for="type">Type</label></td>\
                <td>\
                  <select name="type" id="type">\
                    <option value="">----- Choose Type -----</option>\
                    <option value="A">Service</option>\
                    <option value="B">Supply</option>\
                    <option value="C">Work</option>\
                  </select>\
                </td>\
              </tr>\
              <tr>\
                <td><label for="serviceStartDate">Start Date</label></td>\
                <td><input type="date" id="serviceStartDate" name="serviceStartDate"></td>\
              </tr>\
              <tr>\
                <td><label for="serviceEndDate">End Date</label></td>\
                <td><input type="date" id="serviceEndDate" name="serviceEndDate"></td>\
              </tr>\
              <tr>\
                <td><label for="serviceContract">Contract</label></td>\
                <td><input type="file" id="serviceContract" name="serviceContract"></td>\
              </tr>\
              <tr>\
                <td><label for="serviceClassOrder">Class Order</label></td>\
                <td><input type="file" id="serviceClassOrder" name="serviceClassOrder"></td>\
              </tr>\
              <tr>\
                <td><label for="serviceAcceptanceReport">Acceptance Report</label></td>\
                <td><input type="file" id="serviceAcceptanceReport" name="serviceAcceptanceReport"></td>\
              </tr>\
            </table><br><hr></div>');
            var newFields = $('');

And this is my view :

def becomePartner(request):
    if request.method=="POST":
            if request.FILES['serviceContract'] or request.FILES['serviceClassOrder'] or request.FILES['serviceAcceptanceReport']:
                type = request.POST['type']
                start_date = request.POST['serviceStartDate']
                end_date = request.POST['serviceEndDate']
                contract = Contract.objects.create(start_date=start_date, end_date=end_date, type=type, client=partnerClient)
                if request.FILES['serviceContract']:
                    Document.objects.create(type='A', file=request.FILES['serviceContract'], contract=contract)
                if request.FILES['serviceClassOrder']:
                    Document.objects.create(type='B', file=request.FILES['serviceClassOrder'], contract=contract)
                if request.FILES['serviceAcceptanceReport']:
                    Document.objects.create(type='C', file=request.FILES['serviceAcceptanceReport'], contract=contract)
        return redirect('/ClientManagement')

When I submit , It manipulates just the last form ,and I want to manipulate all the forms.

How Can I solve this ?

Back to Top