From 23fac2bbcc4756158b9cb44d02d052ad98009e5c Mon Sep 17 00:00:00 2001 From: Dmitry Novikov Date: Sat, 29 Jul 2017 13:53:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B4=D0=B0=D1=82=20=D0=BF=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- statistics/models.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/statistics/models.py b/statistics/models.py index 9bf6b38..c222edc 100644 --- a/statistics/models.py +++ b/statistics/models.py @@ -7,6 +7,12 @@ from mydefs import MyGenericIPAddressField from .fields import UnixDateTimeField +def get_dates(): + tables = connection.introspection.table_names() + tables = [t.replace('flowstat_', '') for t in tables if t.startswith('flowstat_')] + return [datetime.strptime(t, '%d%m%Y').date() for t in tables] + + class StatManager(models.Manager): def chart(self, ip_addr, count_of_parts=12, want_date=date.today()): @@ -41,11 +47,6 @@ class StatManager(models.Manager): else: return - def get_dates(self): - tables = connection.introspection.table_names() - tables = [t.replace('flowstat_', '') for t in tables if t.startswith('flowstat_')] - return [datetime.strptime(t, '%d%m%Y').date() for t in tables] - class StatElem(models.Model): cur_time = UnixDateTimeField(primary_key=True) @@ -55,11 +56,19 @@ class StatElem(models.Model): objects = StatManager() + # ReadOnly def save(self, *args, **kwargs): - return + pass + # ReadOnly def delete(self, *args, **kwargs): - return + pass + + def delete_month(self): + cursor = connection.cursor() + table_name = self._meta.db_table + sql = "DROP TABLE %s;" % table_name + cursor.execute(sql) @staticmethod def percentile(N, percent, key=lambda x:x):