Source code for Happyface4.models
from django.db import models
from . import managers
[docs]
class Category(models.Model):
name = models.CharField(max_length=100, verbose_name="Category Name", unique=True)
[docs]
class Instance(models.Model):
name = models.CharField(max_length=100, verbose_name="Analysis Name", unique=True)
[docs]
class InstanceStatus(models.Model):
""":class:`~models.Model` that saves the status of the instances in the db."""
objects = managers.InstanceStatusManager()
time = models.DateTimeField("Time of the status", db_index=True)
category = models.ForeignKey(Category, on_delete=models.CASCADE, db_index=True)
instance = models.ForeignKey(Instance, on_delete=models.CASCADE, db_index=True)
STATUS_CHOICES = [
(-2, "technical issue"), # a technical issue within Happyface ocurred
(-1, "info"), # e.g. it doesn't make sense to provide an status
(0, "ok"), # everything is fine and works as expected
(1, "warning"), # the analysis data goes over the warning threshold
(2, "critical"), # the analysis data goes over the critical threshold
]
status = models.SmallIntegerField(
"status of the instance (-2, 'technical issue'), \
(-1, 'info'), (0, 'ok'), (1, 'warning'), (2, 'critical')",
choices=STATUS_CHOICES,
db_index=True,
)
class Meta:
indexes = [
models.Index(
fields=["instance", "category", "time"],
name="inststat_inst_cat_time_idx",
),
models.Index(fields=["time", "status"], name="inststat_time_status_idx"),
]
ordering = ["-time"]