Skip to content

Commit

Permalink
Work around for miki725#31
Browse files Browse the repository at this point in the history
  • Loading branch information
blackrobot committed Nov 4, 2015
1 parent c8f2106 commit 4c64813
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions rest_framework_bulk/drf3/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,34 @@ def to_internal_value(self, data):
class BulkListSerializer(ListSerializer):
update_lookup_field = 'id'

def to_internal_value(self, data):
try:
return super(BulkListSerializer, self).to_internal_value(data)
except AttributeError:
pass

instance_map = {
getattr(i, self.update_lookup_field): i for i in self.instance
}

ret = []
errors = []
for item in data:
field = item[self.update_lookup_field]
self.child.instance = instance_map.get(field)
try:
validated = self.child.run_validation(item)
except ValidationError as exc:
errors.append(exc.detail)
else:
ret.append(validated)
errors.append({})

if any(errors):
raise ValidationError(errors)

return ret

def update(self, queryset, all_validated_data):
id_attr = getattr(self.child.Meta, 'update_lookup_field', 'id')

Expand Down

0 comments on commit 4c64813

Please sign in to comment.