модель from django db import models class Payer models Model inn model

 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
# модель
from django.db import models
class Payer(models.Model):
inn = models.CharField(max_length = 12)
name = models.CharField(max_length = 400)
def __unicode__(self):
return self.inn + ' - ' + self.name
class Payment(models.Model):
date = models.DateField()
payer = models.ForeignKey('Payer')
tax = models.ForeignKey('Tax')
desc = models.CharField(max_length =400)
amount = models.IntegerField()
def __unicode__(self):
return self.desc
class Register(models.Model):
tax = models.ForeignKey('Tax')
payer = models.ForeignKey('Payer')
date_1 = models.DateField()
payment_1 = models.CharField(max_length = 40)
date_2 = models.DateField()
payment_2 = models.CharField(max_length = 40)
reason = models.CharField(max_length = 400)
class TaxCategory(models.Model):
name = models.CharField(max_length = 70)
def __unicode__(self):
return self.name
class Tax(models.Model):
category = models.ForeignKey('TaxCategory')
code = models.CharField(max_length = 25)
desc = models.CharField(max_length = 400)
def __unicode__(self):
return self.code
# и запрос
query['year0'] = Payer.objects.filter(payment__date__year=period['year0'], payment__date__month=period['month'], payment__tax__category__name=category).annotate(amount=Sum('payment__amount'))