OliveSensorAPI/IOTLLM/SensorAPI/sensors/models.py

19 lines
774 B
Python
Raw Permalink Normal View History

2024-12-10 23:37:45 +08:00
from django.db import models
import uuid
class Sensor(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
area_code = models.CharField(max_length=10)
def __str__(self):
return f"Sensor {self.uuid} in Area {self.area_code}"
class SensorData(models.Model):
sensor = models.ForeignKey(Sensor, on_delete=models.CASCADE, related_name='data', null=True) # 暂时允许 null
parameter_type = models.CharField(max_length=20, default='moisture') # 提供默认值
value = models.DecimalField(max_digits=10, decimal_places=2)
timestamp = models.DateTimeField(auto_now_add=True)
def __str__(self):
return f"Data from Sensor {self.sensor.uuid if self.sensor else 'N/A'} at {self.timestamp}"