Skip to content

Commit

Permalink
[#8] Add question_type to ListDataAnswerSerializer
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed May 22, 2023
1 parent 878f7f7 commit 08f19d5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/AkvoDjangoFormGateway/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ def get_form_name(self, obj):

class ListDataAnswerSerializer(serializers.ModelSerializer):
value = serializers.SerializerMethodField()
question_type = serializers.SerializerMethodField()

class Meta:
model = AkvoGatewayAnswer
fields = ["question", "value"]
fields = ["question", "question_type", "value"]

def get_question_type(self, obj):
return QuestionTypes.FieldStr.get(obj.question.type)

def get_value(self, instance: AkvoGatewayAnswer):
return get_answer_value(instance)
Expand Down
2 changes: 1 addition & 1 deletion src/AkvoDjangoFormGateway/tests/tests_data_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def test_expected_fields_in_data(self):

def test_expected_fields_in_answer(self):
data = self.answer_serializer.data
self.assertEqual(list(data), ["question", "value"])
self.assertEqual(list(data), ["question", "question_type", "value"])
self.assertEqual(str(self.data.first()), self.data.first().name)

def test_value_content_in_answer(self):
Expand Down

0 comments on commit 08f19d5

Please # to comment.