From e4a50dbfa45139db4faa73e9d13abb709d3d1d57 Mon Sep 17 00:00:00 2001 From: James Graham Date: Thu, 20 Feb 2020 15:24:48 +0000 Subject: [PATCH] feat(people): Display relationship answers on detail page resolve #5 --- .../0008_order_answer_by_question.py | 17 ++++++++ people/models.py | 11 +++++ .../templates/people/relationship/detail.html | 43 ++++++++++++++++--- 3 files changed, 66 insertions(+), 5 deletions(-) create mode 100644 people/migrations/0008_order_answer_by_question.py diff --git a/people/migrations/0008_order_answer_by_question.py b/people/migrations/0008_order_answer_by_question.py new file mode 100644 index 0000000..848dd16 --- /dev/null +++ b/people/migrations/0008_order_answer_by_question.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2.10 on 2020-02-20 15:23 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0007_relationship_question_answers'), + ] + + operations = [ + migrations.AlterModelOptions( + name='relationshipquestionchoice', + options={'ordering': ['question__order', 'order', 'text']}, + ), + ] diff --git a/people/models.py b/people/models.py index ba3cf0f..fc3af49 100644 --- a/people/models.py +++ b/people/models.py @@ -97,6 +97,7 @@ class RelationshipQuestionChoice(models.Model): name='unique_question_answer') ] ordering = [ + 'question__order', 'order', 'text', ] @@ -147,3 +148,13 @@ class Relationship(models.Model): def __str__(self) -> str: return f'{self.source} -> {self.target}' + + @property + def reverse(self): + """ + Get the reverse of this relationship. + + @raise Relationship.DoesNotExist: When the reverse relationship is not known + """ + return type(self).objects.get(source=self.target, + target=self.source) diff --git a/people/templates/people/relationship/detail.html b/people/templates/people/relationship/detail.html index 5bcd80c..7198e15 100644 --- a/people/templates/people/relationship/detail.html +++ b/people/templates/people/relationship/detail.html @@ -15,22 +15,55 @@
-
-
+
+

Source

- {{ relationship.source }} +

{{ relationship.source }}

Profile
-
+
+ {% if relationship.reverse %} + + + + {% endif %} +
+ +

Target

- {{ relationship.target }} +

{{ relationship.target }}

Profile
+
+ + + + + + + + + + + {% for answer in relationship.question_answers.all %} + + + + + + {% empty %} + + + + {% endfor %} + +
QuestionAnswer
{{ answer.question }}{{ answer }}
No records
+ {% endblock %}