network_inventory/src/backups/models/backup.py

69 lines
1.8 KiB
Python
Raw Normal View History

2020-01-11 17:01:21 +01:00
from django.db import models
from core.models import Category, Weekday
2020-01-12 14:36:44 +01:00
from computers.models import Computer
2020-01-12 13:18:51 +01:00
from softwares.models import Software
2020-01-11 17:01:21 +01:00
from .notification import Notification
class BackupMethod(Category):
description = models.TextField()
class Meta:
2022-03-27 14:50:44 +02:00
ordering = ["name"]
2020-01-11 17:01:21 +01:00
verbose_name_plural = "Backup Methods"
class Backup(models.Model):
name = models.CharField(max_length=50)
2022-03-27 14:50:44 +02:00
computer = models.ForeignKey(
Computer, related_name="source_computer", on_delete=models.CASCADE
)
method = models.ForeignKey(
BackupMethod, models.SET_NULL, blank=True, null=True
)
software = models.ForeignKey(
Software, models.SET_NULL, blank=True, null=True
)
2020-01-11 17:01:21 +01:00
source_path = models.CharField(max_length=200, blank=True)
exec_time = models.TimeField(null=True, blank=True)
exec_days = models.ManyToManyField(Weekday, blank=True)
2022-03-27 14:50:44 +02:00
target_device = models.ManyToManyField(
Computer, through="TargetDevice", blank=True
)
2020-01-11 17:01:21 +01:00
2020-07-07 22:12:57 +02:00
class Meta:
2022-03-27 14:50:44 +02:00
ordering = ["name"]
2020-07-07 22:12:57 +02:00
2020-01-11 17:01:21 +01:00
def __str__(self):
return str(self.name)
def get_absolute_url(self):
from django.urls import reverse
2022-03-27 14:50:44 +02:00
return reverse("backup", args=[str(self.id)])
2020-01-11 17:01:21 +01:00
@property
def customer(self):
return self.computer.customer
2020-01-11 17:01:21 +01:00
class TargetDevice(models.Model):
2022-03-27 14:50:44 +02:00
device = models.ForeignKey(
Computer, models.SET_NULL, blank=True, null=True
)
2020-01-11 17:01:21 +01:00
backup = models.ForeignKey(Backup, on_delete=models.CASCADE)
target_path = models.CharField(max_length=200, blank=True)
def __str__(self):
return str(self.device)
class Meta:
verbose_name_plural = "Target Devices"
class NotificationFromBackup(models.Model):
backup = models.ForeignKey(Backup, on_delete=models.CASCADE)
notification = models.ForeignKey(Notification, on_delete=models.CASCADE)