From c9c3ac00c1a27ff4bcdb0733789a94c738c35c93 Mon Sep 17 00:00:00 2001 From: Elena ``of Valhalla'' Grandi Date: Fri, 8 Dec 2023 15:11:51 +0100 Subject: Add RRD-related models --- rrd/models.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'rrd/models.py') diff --git a/rrd/models.py b/rrd/models.py index 71a8362..49efd57 100644 --- a/rrd/models.py +++ b/rrd/models.py @@ -1,3 +1,58 @@ from django.db import models +from django.conf import settings +import django.contrib.auth.models as amodels -# Create your models here. + +class ModelWithPerms(models.Model): + users_read = models.ManyToManyField( + amodels.User, + related_name="%(class)s_read" + ) + users_write = models.ManyToManyField( + amodels.User, + related_name="%(class)s_write" + ) + groups_read = models.ManyToManyField( + amodels.Group, + related_name="%(class)s_read" + ) + groups_write = models.ManyToManyField( + amodels.Group, + related_name="%(class)s_write" + ) + + class Meta: + abstract = True + + +class DataSource(ModelWithPerms): + # an mqtt topic can be as long as 65,535 bytes when UTF-8 encoded, + # which is probably too much for a sensible db + topic = models.CharField(max_length=512) + path = models.FilePathField( + path=settings.RRD_DB_PATH, + recursive=True, + max_length=512, + ) + rrd_config = models.TextField() + active = models.BooleanField( + default=True, + ) + + +class Graph(ModelWithPerms): + title = models.CharField(max_length=64) + data_sources = models.ManyToManyField(DataSource) + path = models.FilePathField( + path=settings.RRD_GRAPH_PATH, + recursive=True, + max_length=512, + ) + rrd_config = models.TextField() + + +class Dashboard(ModelWithPerms): + title = models.CharField(max_length=64) + graphs = models.ManyToManyField(Graph) + data_sources = models.ManyToManyField(DataSource) + template = models.TextField() -- cgit v1.2.3