views py class CompanyFinance forms Form receipt forms DecimalField as

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#views.py
class CompanyFinance(forms.Form):
receipt = forms.DecimalField()
asset = forms.DecimalField()
capital_reserve = forms.DecimalField()
def finance(request, id):
try:
company_data = Company.objects.get(pk=id, user=request.user)
finance_report = Company_Finance.objects.filter(company=id)
... ??? ...
CompanyFinanceSet = formset_factory(CompanyFinance, extra=4)
formset = CompanyFinanceSet()
period_data = current_quarter()
if request.method == 'POST':
formset = CompanyFinanceSet(request.POST)
if formset.is_valid():
i = 0
for form in formset.forms:
instance = form.save(commit=False)
instance.company = company_data
instance.period = period_data['def'][i]['Period']
instance.period_year = period_data['def'][i]['Period_Year']
instance.save()
i += 1
return render_to_response('finance.html', {'formset': formset, 'period': period_data['web']})
except Company.DoesNotExist:
return HttpResponseRedirect('/company/new/')
# models.py
class Company_Finance(models.Model):
company = models.ForeignKey(Company)
date_of_create = models.DateTimeField(auto_now_add=True)
period = models.IntegerField()
period_year = models.IntegerField()
receipt = models.CharField(max_length=200)
asset = models.CharField(max_length=200)
capital_reserve = models.CharField(max_length=200)
#tpl
<form action="" method="post">
{{ formset.management_form }}
<div id="table-style">
<table id="content-table" colspan="0" cellspacing="0">
<tr>
<th>&nbsp;</th>
{% for item in period %}
<th>{{ item.Period }} {{ item.Period_Year}} года</th>
{% endfor %}
<!--th>Второй квартал (II) 2009 года</th>
<th>Второй квартал (II) 2009 года</th>
<th>Второй квартал (II) 2009 года</th>
<th>Второй квартал (II) 2009 года</th-->
</tr>
<tr>
<th>Выручка</th>
<td align="center">{{ formset.forms.0.receipt }}</td>
<td align="center">{{ formset.forms.1.receipt }}</td>
<td align="center">{{ formset.forms.2.receipt }}</td>
<td align="center">{{ formset.forms.3.receipt }}</td>
</tr>
<tr>
<th>Активы</th>
<td align="center">{{ formset.forms.0.asset }}</td>
<td align="center">{{ formset.forms.1.asset }}</td>
<td align="center">{{ formset.forms.2.asset }}</td>
<td align="center">{{ formset.forms.3.asset }}</td>
</tr>
<tr>
<th>Капитал резерва</th>
<td align="center">{{ formset.forms.0.capital_reserve }}</td>
<td align="center">{{ formset.forms.1.capital_reserve }}</td>
<td align="center">{{ formset.forms.2.capital_reserve }}</td>
<td align="center">{{ formset.forms.3.capital_reserve }}</td>
</tr>
<tr>
<th colspan="5"><button>Продолжить</button></td>
</tr>
</table>
</div>
</form>