Serializers support bulk create.

This commit is contained in:
Tom Christie 2013-03-09 10:21:53 +00:00
parent 2c6c5d966e
commit 239758e034

View File

@ -391,11 +391,17 @@ class BaseSerializer(Field):
return self._data return self._data
def save_object(self, obj):
obj.save()
def save(self): def save(self):
""" """
Save the deserialized object and return it. Save the deserialized object and return it.
""" """
self.object.save() if isinstance(self.object, list):
[self.save_object(item) for item in self.object]
else:
self.save_object(self.object)
return self.object return self.object
@ -612,11 +618,11 @@ class ModelSerializer(Serializer):
if instance: if instance:
return self.full_clean(instance) return self.full_clean(instance)
def save(self): def save_object(self, obj):
""" """
Save the deserialized object and return it. Save the deserialized object and return it.
""" """
self.object.save() obj.save()
if getattr(self, 'm2m_data', None): if getattr(self, 'm2m_data', None):
for accessor_name, object_list in self.m2m_data.items(): for accessor_name, object_list in self.m2m_data.items():
@ -628,8 +634,6 @@ class ModelSerializer(Serializer):
setattr(self.object, accessor_name, object_list) setattr(self.object, accessor_name, object_list)
self.related_data = {} self.related_data = {}
return self.object
class HyperlinkedModelSerializerOptions(ModelSerializerOptions): class HyperlinkedModelSerializerOptions(ModelSerializerOptions):
""" """