2019-06-10 21:56:21 +02:00
|
|
|
from django.db import models
|
2020-01-12 12:43:01 +01:00
|
|
|
|
|
|
|
from softwares.models import OperatingSystem
|
|
|
|
from softwares.models import Software
|
|
|
|
from softwares.models import SoftwareArchitecture
|
|
|
|
|
2019-06-10 21:56:21 +02:00
|
|
|
from .cpu import Cpu
|
2020-05-03 21:47:45 +02:00
|
|
|
from devices.models import Device
|
2019-06-10 21:56:21 +02:00
|
|
|
from .disk import Disk
|
2020-04-30 15:40:00 +02:00
|
|
|
from .gpu import Gpu
|
2019-06-10 21:56:21 +02:00
|
|
|
from .ram import Ram
|
|
|
|
|
|
|
|
|
2020-05-03 21:47:45 +02:00
|
|
|
class Computer(Device):
|
2022-03-27 14:50:44 +02:00
|
|
|
os = models.ForeignKey(
|
|
|
|
OperatingSystem,
|
|
|
|
models.SET_NULL,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
verbose_name="OS",
|
|
|
|
)
|
|
|
|
cpu = models.ManyToManyField(Cpu, through="ComputerCpuRelation")
|
|
|
|
ram = models.ManyToManyField(Ram, through="ComputerRamRelation")
|
|
|
|
gpu = models.ManyToManyField(Gpu, through="ComputerGpuRelation")
|
|
|
|
disks = models.ManyToManyField(Disk, through="ComputerDiskRelation")
|
|
|
|
software = models.ManyToManyField(
|
|
|
|
Software, through="ComputerSoftwareRelation"
|
|
|
|
)
|
|
|
|
host = models.ForeignKey(
|
|
|
|
"self", null=True, blank=True, on_delete=models.CASCADE
|
|
|
|
)
|
2019-06-10 21:56:21 +02:00
|
|
|
allocated_space = models.IntegerField(null=True, blank=True)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.name)
|
|
|
|
|
|
|
|
class Meta:
|
2022-03-27 14:50:44 +02:00
|
|
|
ordering = ["name"]
|
2019-06-10 21:56:21 +02:00
|
|
|
|
2019-12-10 22:20:34 +01:00
|
|
|
def get_absolute_url(self):
|
|
|
|
from django.urls import reverse
|
2022-03-27 14:50:44 +02:00
|
|
|
|
|
|
|
return reverse("computer", args=[str(self.id)])
|
2019-12-10 22:20:34 +01:00
|
|
|
|
2019-06-10 21:56:21 +02:00
|
|
|
|
|
|
|
class ComputerCpuRelation(models.Model):
|
|
|
|
cpu = models.ForeignKey(Cpu, on_delete=models.CASCADE)
|
|
|
|
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
|
|
|
amount = models.IntegerField()
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-26 22:26:30 +02:00
|
|
|
return str(self.computer)
|
2019-06-10 21:56:21 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = "CPUs in Computer"
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerRamRelation(models.Model):
|
|
|
|
ram = models.ForeignKey(Ram, on_delete=models.CASCADE)
|
|
|
|
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
|
|
|
amount = models.IntegerField()
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-26 22:26:30 +02:00
|
|
|
return str(self.computer)
|
2019-06-10 21:56:21 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = "RAM Modules in Computer"
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerDiskRelation(models.Model):
|
|
|
|
disk = models.ForeignKey(Disk, on_delete=models.CASCADE)
|
|
|
|
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
|
|
|
amount = models.IntegerField()
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-26 22:26:30 +02:00
|
|
|
return str(self.computer)
|
2019-06-10 21:56:21 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = "Disks in Computer"
|
|
|
|
|
|
|
|
|
|
|
|
class ComputerSoftwareRelation(models.Model):
|
|
|
|
software = models.ForeignKey(Software, on_delete=models.CASCADE)
|
|
|
|
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
2022-03-27 14:50:44 +02:00
|
|
|
architecture = models.ForeignKey(
|
|
|
|
SoftwareArchitecture, models.SET_NULL, blank=True, null=True
|
|
|
|
)
|
2019-06-10 21:56:21 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-26 22:26:30 +02:00
|
|
|
return str(self.computer)
|
2019-06-10 21:56:21 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = "Software on Computer"
|
2020-04-30 15:40:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ComputerGpuRelation(models.Model):
|
|
|
|
gpu = models.ForeignKey(Gpu, on_delete=models.CASCADE)
|
|
|
|
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
|
|
|
amount = models.IntegerField()
|
|
|
|
|
|
|
|
def __str__(self):
|
2020-05-26 22:26:30 +02:00
|
|
|
return str(self.computer)
|
2020-04-30 15:40:00 +02:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
verbose_name_plural = "GPUs in Computer"
|