fixed models confusion

This commit is contained in:
Thomas Nahuel Rusiecki 2024-12-01 17:54:22 -03:00
parent e35e6414aa
commit 22d4cea560

View file

@ -10,17 +10,6 @@ class State(models.Model):
state = models.CharField(max_length=50)
snapshot_uuid = models.UUIDField()
class Meta:
unique_together = ('institution', 'state')
def __str__(self):
return f"{self.institution.name} - {self.state} - {self.snapshot_uuid}"
class StateDefinition(models.Model):
institution = models.ForeignKey(Institution, on_delete=models.CASCADE)
order = models.AutoField(primary_key=True)
state = models.CharField(max_length=50)
def clean(self):
if not StateDefinition.objects.filter(institution=self.institution, state=self.state).exists():
raise ValidationError(f"The state '{self.state}' is not valid for the institution '{self.institution.name}'.")
@ -29,5 +18,16 @@ class StateDefinition(models.Model):
self.clean()
super().save(*args, **kwargs)
def __str__(self):
return f"{self.institution.name} - {self.state} - {self.snapshot_uuid}"
class StateDefinition(models.Model):
institution = models.ForeignKey(Institution, on_delete=models.CASCADE)
order = models.AutoField(primary_key=True)
state = models.CharField(max_length=50)
class Meta:
unique_together = ('institution', 'state')
def __str__(self):
return f"{self.institution.name} - {self.state}"