diff --git a/export/serializers/people.py b/export/serializers/people.py index 8c84ccb..196f295 100644 --- a/export/serializers/people.py +++ b/export/serializers/people.py @@ -11,7 +11,7 @@ class SimplePersonSerializer(serializers.ModelSerializer): class Meta: model = models.Person fields = [ - 'pk', + 'id', 'name', ] @@ -20,7 +20,7 @@ class PersonSerializer(base.FlattenedModelSerializer): class Meta: model = models.Person fields = [ - 'pk', + 'id', 'name', 'core_member', 'gender', @@ -28,8 +28,8 @@ class PersonSerializer(base.FlattenedModelSerializer): 'nationality', 'country_of_residence', ] - - + + class RelationshipSerializer(base.FlattenedModelSerializer): source = SimplePersonSerializer() target = SimplePersonSerializer() @@ -37,11 +37,24 @@ class RelationshipSerializer(base.FlattenedModelSerializer): class Meta: model = models.Relationship fields = [ - 'pk', + 'id', 'source', 'target', ] + +class RelationshipAnswerSetSerializer(base.FlattenedModelSerializer): + relationship = RelationshipSerializer() + + class Meta: + model = models.RelationshipAnswerSet + fields = [ + 'id', + 'relationship', + 'timestamp', + 'replaced_timestamp', + ] + @property def column_headers(self) -> typing.List[str]: headers = super().column_headers @@ -57,7 +70,7 @@ class RelationshipSerializer(base.FlattenedModelSerializer): try: # Add relationship question answers to data - for answer in instance.current_answers.question_answers.all(): + for answer in instance.question_answers.all(): rep[answer.question.slug.replace('-', '_')] = answer.slug.replace('-', '_') except AttributeError: diff --git a/export/templates/export/export.html b/export/templates/export/export.html index c94b2df..28a04f6 100644 --- a/export/templates/export/export.html +++ b/export/templates/export/export.html @@ -39,6 +39,15 @@ + + Relationship Answer Sets + + + Export + + + Activities diff --git a/export/urls.py b/export/urls.py index c56fca5..8fed824 100644 --- a/export/urls.py +++ b/export/urls.py @@ -17,6 +17,10 @@ urlpatterns = [ path('export/relationships', views.people.RelationshipExportView.as_view(), name='relationship'), + + path('export/relationship-answer-sets', + views.people.RelationshipAnswerSetExportView.as_view(), + name='relationship-answer-set'), path('export/activities', views.activities.ActivityExportView.as_view(), diff --git a/export/views/people.py b/export/views/people.py index 7f73d5f..a9ff4a6 100644 --- a/export/views/people.py +++ b/export/views/people.py @@ -12,3 +12,8 @@ class PersonExportView(base.CsvExportView): class RelationshipExportView(base.CsvExportView): model = models.relationship.Relationship serializer_class = serializers.people.RelationshipSerializer + + +class RelationshipAnswerSetExportView(base.CsvExportView): + model = models.relationship.RelationshipAnswerSet + serializer_class = serializers.people.RelationshipAnswerSetSerializer