mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Fixed one issue
This commit is contained in:
parent
6f9228ae59
commit
e813baf3eb
|
@ -12,10 +12,10 @@ class ItemAmountSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
class SummarySerializer(serializers.ModelSerializer):
|
class SummarySerializer(serializers.ModelSerializer):
|
||||||
items = ItemAmountSerializer(many=True)
|
items = ItemAmountSerializer(source='itemamount_set', many=True)
|
||||||
|
|
||||||
def create(self, validated_data):
|
def create(self, validated_data):
|
||||||
items = validated_data.pop('items')
|
items = validated_data.pop('itemamount_set')
|
||||||
instance = super().create(validated_data)
|
instance = super().create(validated_data)
|
||||||
for item in items:
|
for item in items:
|
||||||
instance.items.add(
|
instance.items.add(
|
||||||
|
|
|
@ -21,7 +21,7 @@ class TestSerializer(TestCase):
|
||||||
serializer = serializers.SummarySerializer(data=data)
|
serializer = serializers.SummarySerializer(data=data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
expected_data = {
|
expected_data = {
|
||||||
"items": [
|
"itemamount_set": [
|
||||||
{
|
{
|
||||||
"item": item,
|
"item": item,
|
||||||
"amount": 100,
|
"amount": 100,
|
||||||
|
@ -62,5 +62,4 @@ class TestIssueViewSet(TestCase):
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
response = api_client.post(reverse('summary-list'), json.dumps(data), content_type='application/json')
|
response = api_client.post(reverse('summary-list'), json.dumps(data), content_type='application/json')
|
||||||
print(response.content)
|
|
||||||
assert response.status_code == 201
|
assert response.status_code == 201
|
||||||
|
|
Loading…
Reference in New Issue
Block a user