0

我为我的表单制作了以下模板和视图,我想要的是具有不同的标签名称,特别是存储在数组中的每个数据输入字段的 id。请指导我如何实现这一点

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