diff --git a/people/migrations/0032_personquestion_answer_is_public.py b/people/migrations/0032_personquestion_answer_is_public.py new file mode 100644 index 0000000..97d8ca5 --- /dev/null +++ b/people/migrations/0032_personquestion_answer_is_public.py @@ -0,0 +1,18 @@ +# Generated by Django 2.2.10 on 2021-02-08 13:32 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('people', '0031_question_allow_free_text'), + ] + + operations = [ + migrations.AddField( + model_name='personquestion', + name='answer_is_public', + field=models.BooleanField(default=True, help_text='Should answers to this question be displayed on profiles?'), + ), + ] diff --git a/people/models/person.py b/people/models/person.py index 914c53d..2b20564 100644 --- a/people/models/person.py +++ b/people/models/person.py @@ -95,6 +95,12 @@ class Theme(models.Model): class PersonQuestion(Question): """Question which may be asked about a person.""" + #: Should answers to this question be displayed on public profiles? + answer_is_public = models.BooleanField( + help_text='Should answers to this question be displayed on profiles?', + default=True, + blank=False, + null=False) class PersonQuestionChoice(QuestionChoice): @@ -193,6 +199,10 @@ class PersonAnswerSet(AnswerSet): #: Longitude for displaying location on a map longitude = models.FloatField(blank=True, null=True) + def public_answers(self) -> models.QuerySet: + """Get answers to questions which are public.""" + return self.question_answers.filter(question__answer_is_public=True) + def as_dict(self): """Get the answers from this set as a dictionary for use in Form.initial.""" exclude_fields = { diff --git a/people/templates/people/person/includes/answer_set_partial.html b/people/templates/people/person/includes/answer_set_partial.html index ccd6dd8..2e96e5f 100644 --- a/people/templates/people/person/includes/answer_set_partial.html +++ b/people/templates/people/person/includes/answer_set_partial.html @@ -15,7 +15,7 @@ Organisation{{ answer_set.organisation }} {% endif %} - {% for answer in answer_set.question_answers.all %} + {% for answer in answer_set.public_answers.all %} {{ answer.question }} {{ answer }}