from django.db import models from django.conf import settings import uuid def getRandom(): return str(uuid.uuid4().hex) class Organization(models.Model): name = models.CharField(max_length=300) users = models.ManyToManyField(settings.AUTH_USER_MODEL) def __str__(self): return self.name class Network(models.Model): extip = models.CharField(max_length=15) intip = models.CharField(max_length=15) organizations = models.ManyToManyField(Organization) def __str__(self): return "%s (%s)" % (self.intip, self.extip) class Device(models.Model): serial = models.CharField("Device Serial Number", max_length=12, unique=True) name = models.CharField("Common Name", max_length=100, blank=True, null=True) organization = models.ForeignKey(Organization, on_delete=models.CASCADE) network = models.OneToOneField(Network, on_delete=models.SET_NULL, blank=True, null=True) curip = models.CharField("Current IP Address", max_length=15, blank=True, null=True) lasttime = models.DateTimeField("Last Received Heartbeat", blank=True, null=True) secret = models.CharField("Secret", default=getRandom, max_length=128) def __str__(self): return "%s%s" % (self.serial, " (%s)" % self.curip if self.curip else "")