[Update] 修改Model

pull/1053/head
ibuler 7 years ago
parent 5cc43f6907
commit d3fa3d63e7

@ -127,7 +127,7 @@ class Session(models.Model):
is_finished = models.BooleanField(default=False) is_finished = models.BooleanField(default=False)
has_replay = models.BooleanField(default=False, verbose_name=_("Replay")) has_replay = models.BooleanField(default=False, verbose_name=_("Replay"))
has_command = models.BooleanField(default=False, verbose_name=_("Command")) has_command = models.BooleanField(default=False, verbose_name=_("Command"))
terminal = models.ForeignKey(Terminal, null=True, on_delete=models.CASCADE) terminal = models.ForeignKey(Terminal, null=True, on_delete=models.SET_NULL)
date_last_active = models.DateTimeField(verbose_name=_("Date last active"), default=timezone.now) date_last_active = models.DateTimeField(verbose_name=_("Date last active"), default=timezone.now)
date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True) date_start = models.DateTimeField(verbose_name=_("Date start"), db_index=True)
date_end = models.DateTimeField(verbose_name=_("Date end"), null=True) date_end = models.DateTimeField(verbose_name=_("Date end"), null=True)
@ -148,7 +148,7 @@ class Task(models.Model):
id = models.UUIDField(default=uuid.uuid4, primary_key=True) id = models.UUIDField(default=uuid.uuid4, primary_key=True)
name = models.CharField(max_length=128, choices=NAME_CHOICES, verbose_name=_("Name")) name = models.CharField(max_length=128, choices=NAME_CHOICES, verbose_name=_("Name"))
args = models.CharField(max_length=1024, verbose_name=_("Args")) args = models.CharField(max_length=1024, verbose_name=_("Args"))
terminal = models.ForeignKey(Terminal, null=True, on_delete=models.CASCADE) terminal = models.ForeignKey(Terminal, null=True, on_delete=models.SET_NULL)
is_finished = models.BooleanField(default=False) is_finished = models.BooleanField(default=False)
date_created = models.DateTimeField(auto_now_add=True) date_created = models.DateTimeField(auto_now_add=True)
date_finished = models.DateTimeField(null=True) date_finished = models.DateTimeField(null=True)

@ -31,6 +31,6 @@ def delete_terminal_status_period():
def clean_orphan_session(): def clean_orphan_session():
active_sessions = Session.objects.filter(is_finished=False) active_sessions = Session.objects.filter(is_finished=False)
for session in active_sessions: for session in active_sessions:
if not session.terminal.is_active: if not session.terminal or not session.terminal.is_active:
session.is_finished = True session.is_finished = True
session.save() session.save()

Loading…
Cancel
Save