class IncidentRelationType(models.Model):
name = models.TextField()
class Meta:
ordering = ["name"]
def __str__(self):
return self.name
class IncidentRelation(models.Model):
# "+" prevents creating a backwards relation
incident1 = models.ForeignKey(to=Incident, on_delete=models.CASCADE, related_name="+")
incident2 = models.ForeignKey(to=Incident, on_delete=models.CASCADE, related_name="+")
type = models.ForeignKey(to=IncidentRelationType, on_delete=models.PROTECT, related_name="incident_relations")
description = models.TextField(blank=True)
def __str__(self):
return f"Incident #{self.incident1.pk} {self.type} #{self.incident2.pk}"
See also PR #312, which so far ensures that incident1 and incident2 cannot be identical.
If name is "duplicate", str(IncidentRelation) would look something like "Incident #32 duplicate #17", which is not very useful.
See also PR #312, which so far ensures that
incident1andincident2cannot be identical.If
nameis"duplicate",str(IncidentRelation)would look something like"Incident #32 duplicate #17", which is not very useful.