| | |
| | | from django.db import models |
| | | |
| | | |
| | | # Create your models here. |
| | | |
| | | |
| | | class SensorType(models.Model): |
| | | name = models.CharField(max_length=30) |
| | | unit = models.CharField(max_length=10) |
| | | |
| | | def __str__(self): |
| | | return self.name |
| | | |
| | | |
| | | class Sensor(models.Model): |
| | | sensor_type = models.ForeignKey(SensorType, on_delete=models.CASCADE) |
| | | name = models.CharField(max_length=30) |
| | | |
| | | def __str__(self): |
| | | return self.name |
| | | |
| | | |
| | | class Measurement(models.Model): |
| | | sensor_id = models.ForeignKey(Sensor, on_delete=models.CASCADE) |
| | | value = models.FloatField() |
| | | timestamp = models.DateTimeField(auto_now_add=True) |
| | | |
| | | def __str__(self): |
| | | return "{} {} {} {}".format(self.sensor_id, self.value, self.sensor_id.sensor_type.unit, self.timestamp) |