Fixed one issue

This commit is contained in:
enrico 2022-08-30 12:45:57 +08:00
parent 6f9228ae59
commit e813baf3eb
2 changed files with 3 additions and 4 deletions

View File

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

View File

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