From 7210ab5e5b2657e20bad2a5d659cf63492dae078 Mon Sep 17 00:00:00 2001 From: xianfuxing Date: Wed, 28 Aug 2019 21:11:23 +0800 Subject: [PATCH] =?UTF-8?q?#=20add=20=E6=B8=A9=E5=BA=A6=E6=B9=BF=E5=BA=A6?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +-- apps/mosquito/migrations/0010_initial.py | 26 ++++++++++++++++++++++++ apps/mosquito/migrations/__init__.py | 0 apps/mosquito/models.py | 16 +++++++++++++++ mosqkiller/settings.py | 3 ++- 5 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 apps/mosquito/migrations/0010_initial.py create mode 100644 apps/mosquito/migrations/__init__.py diff --git a/.gitignore b/.gitignore index 20696b4..91dd011 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.pyc __pycache__ .idea -db.sqlite3 -migrations \ No newline at end of file +db.sqlite3 \ No newline at end of file diff --git a/apps/mosquito/migrations/0010_initial.py b/apps/mosquito/migrations/0010_initial.py new file mode 100644 index 0000000..9fe9af5 --- /dev/null +++ b/apps/mosquito/migrations/0010_initial.py @@ -0,0 +1,26 @@ +# Generated by Django 2.0.7 on 2019-08-28 13:04 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + operations = [ + migrations.CreateModel( + name='DeviceTempLog', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('device_id', models.CharField(max_length=100, verbose_name='设备ID')), + ('temperature', models.DecimalField(decimal_places=2, max_digits=6, verbose_name='温度')), + ('humidity', models.DecimalField(decimal_places=2, max_digits=6, verbose_name='湿度')), + ('last_time', models.DateTimeField(blank=True, null=True, verbose_name='日志时间')), + ('create_time', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')), + ], + options={ + 'verbose_name': '设备温度湿度日志', + 'verbose_name_plural': '设备温度湿度日志', + }, + ), + ] diff --git a/apps/mosquito/migrations/__init__.py b/apps/mosquito/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/apps/mosquito/models.py b/apps/mosquito/models.py index 0f2d6ac..72ef7e2 100644 --- a/apps/mosquito/models.py +++ b/apps/mosquito/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils.timezone import datetime from django.contrib.contenttypes.fields import GenericRelation from smart.models import SmartModule, SmartPush @@ -86,3 +87,18 @@ class Org(models.Model): class DeviceInfo(models.Model): device_id = models.CharField(max_length=100, unique=True, verbose_name='设备ID') org = models.ForeignKey(Org, verbose_name='所在组织', on_delete='PROTECT') + + +class DeviceTempLog(models.Model): + device_id = models.CharField(max_length=100, verbose_name='设备ID') + temperature = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='温度') + humidity = models.DecimalField(max_digits=6, decimal_places=2, verbose_name='湿度') + last_time = models.DateTimeField(null=True, blank=True, verbose_name='日志时间') + create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间') + + class Meta: + verbose_name = '设备温度湿度日志' + verbose_name_plural = verbose_name + + def __str__(self): + return self.device_id diff --git a/mosqkiller/settings.py b/mosqkiller/settings.py index 17b0a1b..ab40a2b 100644 --- a/mosqkiller/settings.py +++ b/mosqkiller/settings.py @@ -99,7 +99,8 @@ DATABASES = { 'USER': 'mosq_admin', 'PASSWORD': 'Q5BkPk62mqeBxI_lHh2', 'HOST': '47.106.73.20', - 'PORT': 3326 + 'PORT': 3326, + 'OPTIONS': {'init_command': 'SET sql_mode="STRICT_TRANS_TABLES"'} }, 'counter': { 'ENGINE': 'django.db.backends.mysql',