mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 12:00:12 +03:00
Put default files=None back on BaseSerializer.from_native
* In ListField and DictField methods, place field check before list or dict construction
This commit is contained in:
parent
b0027e52fa
commit
f21f009fd1
|
@ -6,12 +6,6 @@ from .fields import WritableField
|
||||||
from .serializers import BaseSerializer
|
from .serializers import BaseSerializer
|
||||||
|
|
||||||
|
|
||||||
def field_or_serializer_from_native(field_or_serializer, data):
|
|
||||||
if isinstance(field_or_serializer, BaseSerializer):
|
|
||||||
return field_or_serializer.from_native(data, None)
|
|
||||||
return field_or_serializer.from_native(data)
|
|
||||||
|
|
||||||
|
|
||||||
class ListField(WritableField):
|
class ListField(WritableField):
|
||||||
"""
|
"""
|
||||||
A field whose values are lists of items described by the given item field. The item field can
|
A field whose values are lists of items described by the given item field. The item field can
|
||||||
|
@ -23,18 +17,17 @@ class ListField(WritableField):
|
||||||
self.item_field = item_field
|
self.item_field = item_field
|
||||||
|
|
||||||
def to_native(self, obj):
|
def to_native(self, obj):
|
||||||
if obj:
|
if self.item_field and obj:
|
||||||
return [
|
return [
|
||||||
self.item_field.to_native(item) if self.item_field else item
|
self.item_field.to_native(item)
|
||||||
for item in obj
|
for item in obj
|
||||||
]
|
]
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def from_native(self, data):
|
def from_native(self, data):
|
||||||
if data:
|
if self.item_field and data:
|
||||||
return [
|
return [
|
||||||
field_or_serializer_from_native(self.item_field, item_data)
|
self.item_field.from_native(item_data)
|
||||||
if self.item_field else item_data
|
|
||||||
for item_data in data
|
for item_data in data
|
||||||
]
|
]
|
||||||
return data
|
return data
|
||||||
|
@ -51,21 +44,17 @@ class DictField(WritableField):
|
||||||
self.value_field = value_field
|
self.value_field = value_field
|
||||||
|
|
||||||
def to_native(self, obj):
|
def to_native(self, obj):
|
||||||
if obj:
|
if self.value_field and obj:
|
||||||
return dict(
|
return dict(
|
||||||
(key, self.value_field.to_native(value) if self.value_field else value)
|
(unicode(key), self.value_field.to_native(value))
|
||||||
for key, value in obj.items()
|
for key, value in obj.items()
|
||||||
)
|
)
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
def from_native(self, data):
|
def from_native(self, data):
|
||||||
if data:
|
if self.value_field and data:
|
||||||
return dict(
|
return dict(
|
||||||
(
|
(unicode(key), self.value_field.from_native(value))
|
||||||
unicode(key),
|
|
||||||
field_or_serializer_from_native(self.value_field, value)
|
|
||||||
if self.value_field else value
|
|
||||||
)
|
|
||||||
for key, value in data.items()
|
for key, value in data.items()
|
||||||
)
|
)
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -331,7 +331,7 @@ class BaseSerializer(WritableField):
|
||||||
|
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
def from_native(self, data, files):
|
def from_native(self, data, files=None):
|
||||||
"""
|
"""
|
||||||
Deserialize primitives -> objects.
|
Deserialize primitives -> objects.
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user