Merge commit '19dcdc5442728451540d764f674f299cc2a80d48' into pk_related

* commit '19dcdc5442728451540d764f674f299cc2a80d48':
  Try to recover an object by its ID before duplicating it.
This commit is contained in:
Ze'ev Gilovitz 2014-05-23 10:37:32 +08:00
commit 55dfbcd42a

View File

@ -526,6 +526,11 @@ class BaseSerializer(WritableField):
# Determine which object we're updating
identity = self.get_identity(item)
self.object = identity_to_objects.pop(identity, None)
if not self.object and getattr(self.opts, 'model', None):
try:
self.object = self.opts.model.objects.get(id=self.get_identity(item))
except ObjectDoesNotExist:
pass
if self.object is None and not self.allow_add_remove:
ret.append(None)
errors.append({'non_field_errors': ['Cannot create a new item, only existing items may be updated.']})