import django.contrib.auth.models as amodels from django.conf import settings from django.db import models 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()