From e813baf3eb8d2cb15d0e8f012bef00d608f9b514 Mon Sep 17 00:00:00 2001 From: enrico Date: Tue, 30 Aug 2022 12:45:57 +0800 Subject: [PATCH] Fixed one issue --- tests/issue/serializers.py | 4 ++-- tests/issue/test_issue.py | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/issue/serializers.py b/tests/issue/serializers.py index b94a1b091..6b7d68b51 100644 --- a/tests/issue/serializers.py +++ b/tests/issue/serializers.py @@ -12,10 +12,10 @@ class ItemAmountSerializer(serializers.ModelSerializer): class SummarySerializer(serializers.ModelSerializer): - items = ItemAmountSerializer(many=True) + items = ItemAmountSerializer(source='itemamount_set', many=True) def create(self, validated_data): - items = validated_data.pop('items') + items = validated_data.pop('itemamount_set') instance = super().create(validated_data) for item in items: instance.items.add( diff --git a/tests/issue/test_issue.py b/tests/issue/test_issue.py index 72ca491d3..96f07b757 100644 --- a/tests/issue/test_issue.py +++ b/tests/issue/test_issue.py @@ -21,7 +21,7 @@ class TestSerializer(TestCase): serializer = serializers.SummarySerializer(data=data) serializer.is_valid(raise_exception=True) expected_data = { - "items": [ + "itemamount_set": [ { "item": item, "amount": 100, @@ -62,5 +62,4 @@ class TestIssueViewSet(TestCase): ], } response = api_client.post(reverse('summary-list'), json.dumps(data), content_type='application/json') - print(response.content) assert response.status_code == 201