Enhance AnatomyQuestion string representation; improve formatting and handle missing attributes for better readability
This commit is contained in:
+10
-8
@@ -132,14 +132,16 @@ class AnatomyQuestion(QuestionBase):
|
||||
return "anatomy"
|
||||
|
||||
def __str__(self):
|
||||
# Get first answer
|
||||
return "{}/{}: {} [{}, {}]".format(
|
||||
self.pk,
|
||||
self.question_type,
|
||||
self.get_primary_answer(),
|
||||
self.modality,
|
||||
self.structure,
|
||||
)
|
||||
# Nicely formatted representation
|
||||
pk = self.pk or ""
|
||||
qtype = str(self.question_type) if self.question_type else "N/A"
|
||||
primary = self.get_primary_answer() or "None"
|
||||
modality = str(self.modality) if self.modality else "Unknown"
|
||||
structure = str(self.structure) if self.structure else "Unknown"
|
||||
title = self.get_title() if hasattr(self, "get_title") else (self.description or "")
|
||||
if title and len(title) > 60:
|
||||
title = title[:57] + "..."
|
||||
return f"{title} (Type: {qtype}) — Answer: {primary} — Modality: {modality}; Structure: {structure}"
|
||||
|
||||
def get_link(self):
|
||||
return format_html("<a href='{}'>{}</a>", self.get_absolute_url(), self)
|
||||
|
||||
Reference in New Issue
Block a user