update conditions to use through for self links

This commit is contained in:
Ross
2023-11-06 11:16:59 +00:00
parent bbcfe7d80c
commit 369b1970a3
12 changed files with 232 additions and 6 deletions
+20 -1
View File
@@ -144,7 +144,7 @@ class Condition(SynMixin, models.Model):
name = models.CharField(max_length=255, unique=True)
synonym = models.ManyToManyField("self", blank=True)
parent = models.ManyToManyField("self", blank=True)
parent = models.ManyToManyField("self", blank=True, related_name="child", symmetrical=False, through="ConditionRelationship")
primary = models.BooleanField(default="True")
@@ -157,6 +157,25 @@ class Condition(SynMixin, models.Model):
def get_absolute_url(self):
return reverse("atlas:condition_detail", kwargs={"pk": self.pk})
def get_children(self):
return self.child.all()
def get_descendents(self):
"""TODO"""
def get_parents(self):
return self.parent.all()
class ConditionRelationship(models.Model):
child = models.ForeignKey(Condition, on_delete=models.CASCADE)
parent = models.ForeignKey(Condition, on_delete=models.CASCADE, related_name="+")
relationship_type = models.CharField(max_length=255, blank=True, null=True)
def __str__(self):
return f"{self.parent} -> {self.child}"
class Presentation(models.Model):
name = models.CharField(max_length=255)