forked from rc/aircox
cfr #121 Co-authored-by: Christophe Siraut <d@tobald.eu.org> Co-authored-by: bkfox <thomas bkfox net> Co-authored-by: Thomas Kairos <thomas@bkfox.net> Reviewed-on: rc/aircox#131 Co-authored-by: Chris Tactic <ctactic@noreply.git.radiocampus.be> Co-committed-by: Chris Tactic <ctactic@noreply.git.radiocampus.be>
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.db import models
|
||||
from django.db.models import F, Q
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .program import Program
|
||||
@ -45,7 +46,7 @@ class Rerun(models.Model):
|
||||
models.SET_NULL,
|
||||
related_name="rerun_set",
|
||||
verbose_name=_("rerun of"),
|
||||
limit_choices_to={"initial__isnull": True},
|
||||
limit_choices_to=Q(initial__isnull=True) & Q(program=F("program")),
|
||||
blank=True,
|
||||
null=True,
|
||||
db_index=True,
|
||||
@ -74,7 +75,10 @@ class Rerun(models.Model):
|
||||
raise ValidationError({"initial": _("rerun must happen after original")})
|
||||
|
||||
def save_rerun(self):
|
||||
self.program = self.initial.program
|
||||
if not self.program_id:
|
||||
self.program = self.initial.program
|
||||
if self.program != self.initial.program:
|
||||
raise ValidationError("Program for the rerun should be the same")
|
||||
|
||||
def save_initial(self):
|
||||
pass
|
||||
|
Reference in New Issue
Block a user