-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodels.py
58 lines (43 loc) · 2.2 KB
/
models.py
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
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from itcap.models import Organization
class Org(models.Model):
org = models.ForeignKey(Organization, verbose_name=u'Организация')
stat_all = models.ManyToManyField('Stats', verbose_name=u'Статистика', related_name='statistics', blank=True,
null=True)
def __unicode__(self):
return self.org.name
class Meta:
verbose_name_plural = u'Статистика организации'
verbose_name = u'Статистика организации'
def get_sum(self):
st_sum = 0
for month in self.stat_all.all():
st_sum += month.sum_all
return st_sum
class OrgGroup(models.Model):
name = models.CharField(u'Наименование группы', max_length=500)
description = models.TextField(u'Описание')
orgs = models.ManyToManyField('Org', verbose_name=u'Статистика организаций', related_name='stat_org')
def __unicode__(self):
return self.name
class Meta:
verbose_name_plural = u'Группа статистики'
verbose_name = u'Группа статистики'
class Stats(models.Model):
period = models.DateField(u'Период статистики')
calls = models.PositiveIntegerField(u'Количество обращений')
requests = models.PositiveIntegerField(u'Количество запросов')
created = models.DateTimeField(u'Создано', auto_now_add=True)
modified = models.DateTimeField(u'Изменено', auto_now=True)
user_created = models.ForeignKey(User, verbose_name=u'Создал', related_name='user_created')
user_changed = models.ForeignKey(User, verbose_name=u'Изменил', related_name='user_changed', null=True, blank=True)
def __unicode__(self):
return str(self.period)
class Meta:
verbose_name_plural = u'Статистика за месяц'
verbose_name = u'Статистика за месяц'
permissions = (
("edit_stats", u"Может редактировать статистику"),
)