feat(people): Display relationship answers on detail page

resolve #5
This commit is contained in:
James Graham
2020-02-20 15:24:48 +00:00
parent 5a1b043862
commit e4a50dbfa4
3 changed files with 66 additions and 5 deletions

View File

@@ -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']},
),
]

View File

@@ -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)

View File

@@ -15,22 +15,55 @@
<hr>
<div class="row align-content-center">
<div class="col-md-6">
<div class="row align-content-center align-items-center">
<div class="col-md-5 text-center">
<h2>Source</h2>
{{ relationship.source }}
<p>{{ relationship.source }}</p>
<a class="btn btn-sm btn-info"
href="{% url 'people:person.detail' pk=relationship.source.pk %}">Profile</a>
</div>
<div class="col-md-6">
<div class="col-md-2 text-center">
{% if relationship.reverse %}
<a href="{% url 'people:relationship.detail' pk=relationship.reverse.pk %}">
<span class="fas fa-exchange-alt fa-5x"></span>
</a>
{% endif %}
</div>
<div class="col-md-5 text-center">
<h2>Target</h2>
{{ relationship.target }}
<p>{{ relationship.target }}</p>
<a class="btn btn-sm btn-info"
href="{% url 'people:person.detail' pk=relationship.target.pk %}">Profile</a>
</div>
</div>
<hr>
<table class="table table-borderless">
<thead>
<tr>
<th>Question</th>
<th>Answer</th>
</tr>
</thead>
<tbody>
{% for answer in relationship.question_answers.all %}
<tr>
<td>{{ answer.question }}</td>
<td>{{ answer }}</td>
</tr>
{% empty %}
<tr>
<td>No records</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}