convert backup exec_days to a many-to-many field

This commit is contained in:
Andreas Zweili 2020-04-30 19:20:53 +02:00
parent 0aa4a43e13
commit 43e8dcc14c
3 changed files with 22 additions and 3 deletions

View File

@ -24,8 +24,7 @@ class Backup(models.Model):
null=True)
source_path = models.CharField(max_length=200, blank=True)
exec_time = models.TimeField()
exec_day = models.ForeignKey(Weekday, models.SET_NULL, blank=True,
null=True)
exec_days = models.ManyToManyField(Weekday)
target_device = models.ManyToManyField(Computer, through='TargetDevice')
def __str__(self):

View File

@ -27,7 +27,9 @@
</tr>
<tr>
<td><b>Exec Day:</b></td>
<td>{{ backup.exec_day }}</td>
<td>
{% for backup in backup.exec_days.all %}{{ backup }}<br/>{% endfor %}
</td>
</tr>
</table>
</div>

View File

@ -3,6 +3,7 @@ from mixer.backend.django import mixer
from django.test import Client
from core.tests import helper
from core.models import Weekday
from customers.models import Customer
pytestmark = pytest.mark.django_db
@ -72,3 +73,20 @@ def test_backup_detail_view_with_notification(create_admin_user):
response = client.get('/backup/' + str(backup.id) + '/')
assert (response.status_code == 200
and helper.in_content(response, notification))
def test_backup_detail_view_with_day_relation(create_admin_user):
create_admin_user()
mixer.blend('computers.Computer', customer=mixer.SELECT)
monday = Weekday.objects.filter(name="Monday")
wednesday = Weekday.objects.filter(name="Wednesday")
backup = mixer.blend('backups.Backup',
computer=mixer.SELECT)
backup.exec_days.add(monday[0])
backup.exec_days.add(wednesday[0])
client = Client()
client.login(username="pharma-admin", password="password")
response = client.get('/backup/' + str(backup.id) + '/')
assert (response.status_code == 200
and helper.in_content(response, monday[0])
and helper.in_content(response, wednesday[0]))