start database
This commit is contained in:
1
sites/WeatherStation/.gitignore
vendored
1
sites/WeatherStation/.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
db.sqlite3
|
||||
*/__pycache__
|
||||
*/migrations
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import Sensor, Measurement
|
||||
# Register your models here.
|
||||
admin.site.register(Sensor)
|
||||
admin.site.register(Measurement)
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
class Sensor(models.Model):
|
||||
name = models.CharField(max_length=20, default="bedroom-bme280-01")
|
||||
temperature_unit = models.CharField(max_length=5, default="C")
|
||||
pressure_unit = models.CharField(max_length=5, default="hPa")
|
||||
humidity_unit = models.CharField(max_length=5, default="%")
|
||||
def __str__(self):
|
||||
return f"Sensor {self.name}, units are C (temperature), hPa (pressure) and % (humidity)"
|
||||
|
||||
class Measurement(models.Model):
|
||||
time = models.DateTimeField('timestamp', auto_now=True)
|
||||
temperature = models.FloatField(default=-400)
|
||||
humidity = models.FloatField(default=-1)
|
||||
pressure = models.FloatField(default=-1)
|
||||
def __str__(self):
|
||||
return f"{self.time}, {self.temperature} C, {self.pressure} hPa, {self.humidity} %"
|
||||
|
||||
@@ -31,6 +31,7 @@ ALLOWED_HOSTS = []
|
||||
# Application definition
|
||||
|
||||
INSTALLED_APPS = [
|
||||
'HomeWeather.apps.HomeweatherConfig',
|
||||
'django.contrib.admin',
|
||||
'django.contrib.auth',
|
||||
'django.contrib.contenttypes',
|
||||
|
||||
Reference in New Issue
Block a user