diff options
author | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-12-08 15:11:51 +0100 |
---|---|---|
committer | Elena ``of Valhalla'' Grandi <valhalla@trueelena.org> | 2023-12-29 07:29:15 +0100 |
commit | c9c3ac00c1a27ff4bcdb0733789a94c738c35c93 (patch) | |
tree | e3065ad59a87c4c01f136a19efda31587d5ae8b8 /rrd/models.py | |
parent | 0195aa4ce2010061b42bacd0b3e13d88007ffacc (diff) |
Add RRD-related models
Diffstat (limited to 'rrd/models.py')
-rw-r--r-- | rrd/models.py | 57 |
1 files changed, 56 insertions, 1 deletions
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() |