I'm looking into creating some kind of dashboard to do some easy server admin tasks online. As much as possible stored in the database, so I could configure there tasks online instead of programming them.
What I'm trying to achieve in my data model is the following:
I have a model for Applications:
class Application(models.Model):
name = models.CharField(max_length=30)
def __str__(self):
return self.name
In my Server model I have ManyToManyField mapping to my Applications model so I could select one or more applications which run on this server:
from applications.models import Application
class Server(models.Model):
name = models.CharField(max_length=20,blank=False, null=False)
application = models.ManyToManyField(Application, blank=True, related_name='applications')
ip = models.CharField(max_length=15, blank=True)
dns = models.CharField(max_length=100, blank=True)
To support multiple server types (web server, database), I have a Servertype model:
from applications.models import Application
class Servertype(models.Model):
application = models.ForeignKey(Application, on_delete=models.CASCADE)
type = models.CharField(max_length=20, blank=False, null=False)
order = models.IntegerField(null=False)
def __str__(self):
return "%s - %s" % (self.application, self.type)
class Meta:
ordering = ["application", "order"]
Now I want to map these last 2 together, so I could link up Server and Servertype, but limit the Servertype choices to whatever is chosen as Application in Server, and is defined for this Application in Servertype. But I'm not fully sure how this would work. Certainly not like this:
from servers.models import Server
from applications.models import Application
class ServerServertype(models.Model):
server = models.ForeignKey(Server, on_delete=models.CASCADE)
applications = models.ForeignKey(Application, on_delete=models.CASCADE, limit_choices_to=Server)
Anyone an idea?