2020-06-02 00:57:20 +02:00
|
|
|
from django.db import models
|
2020-06-03 18:53:33 +02:00
|
|
|
from django.core.validators import MinValueValidator
|
2020-06-02 00:57:20 +02:00
|
|
|
from django.contrib.postgres.fields import JSONField
|
|
|
|
|
|
|
|
from api.models import Device
|
|
|
|
|
|
|
|
|
|
|
|
class Telemetry(models.Model):
|
|
|
|
device = models.ForeignKey(Device, on_delete=models.CASCADE)
|
2020-06-02 23:34:11 +02:00
|
|
|
time = models.DateTimeField(primary_key=True, auto_now_add=True)
|
2020-06-08 23:17:16 +02:00
|
|
|
transport = models.CharField(max_length=4,
|
|
|
|
choices=[('http', 'http'), ('mqtt', 'mqtt')],
|
|
|
|
default='http')
|
2020-06-03 18:53:33 +02:00
|
|
|
clock = models.IntegerField(
|
|
|
|
validators=[MinValueValidator(0)],
|
|
|
|
null=True)
|
2020-06-02 00:57:20 +02:00
|
|
|
payload = JSONField()
|
|
|
|
|
|
|
|
class Meta:
|
2020-06-03 18:53:33 +02:00
|
|
|
ordering = ['-time', 'device']
|
2020-06-02 00:57:20 +02:00
|
|
|
verbose_name_plural = "Telemetry"
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-06-03 18:53:33 +02:00
|
|
|
return str(self.time)
|