0

私は自分のフォーム用に次のテンプレートとビューを作成しました。私が望むのは、データ入力フィールドごとに配列に格納されている ID に具体的に名前を付けるさまざまなラベルを付けることです.Plz はこれを達成する方法を教えてくれます

def show (request):

b = request.session["s1"] # count of no of period ids
c = request.session["s2"] # account number inserted by user
d = request.session["s3"] # year inserted by customer
a = account_period.objects.filter(year=d).values('id')
e = account_period.objects.filter(year=d).values('month')
f = account_period.objects.filter(id = a).values('year')
butt = formset_factory(bu, extra=b)
if request.method == 'POST'
 formset = butt(request.POST)
 if formset.is_valid():

    z = account_tab.objects.get(account_number=c)
    pr = date.today()
    i=0
    for form in formset.forms:
       x = form.cleaned_data['value']
       y = account_period.objects.get(id=a[i:(i+1)])
       try:
        uip = budget.objects.get(account_no = c,account_period = a[i:(i+1)])
        if uip.budget_amount != x
          uip.budget_amount = x
          uip.save()

       except budget.DoesNotExist:
        w = budget(account_no = z, account_period = y, budget_amount = x, created_by_login = 'me')
        w.save()
       i=i+1
    pass
  return HttpResponse('thanks')


else:
  formset = butt(
   return render_to_response('budgetfinalform.html', {'account_number': c,'period':d,'month':e,'year':f,'formset': formset},context_instance=RequestContext(request))



<html>
<head>
<title>BUDGET</title>
</head>
<body>
<p>BUDGET MANAGEMENTS</p>
<p>Your Account Number is : {{ account_number }}.</p> <p>You Chose {{ period }} {{month}} as period<p>   
{% if form.errors %}
<p style="color: red;">
    Please correct the error{{ form.errors|pluralize }} below.
</p>
{% endif %} 
<form action="." method="post">{% csrf_token %}
{{ formset.management_form }}
<table>
{% for form in formset.forms %}
{{ form }}
{% endfor %}
</table>    
<input type="submit" value="Submit">
</form>
</body>
</html>
4

0 に答える 0