Created
May 19, 2014 16:36
-
-
Save awentzonline/0009a444d2d3281b0b0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def from_native(self, data, files): | |
| identity = self.get_identity(data) | |
| if identity: | |
| obj = self.opts.model.objects.get(id=identity) | |
| dirty = False | |
| for field_name, field_serializer in self.fields.items(): | |
| val = field_serializer.from_native(data[field_name]) | |
| if getattr(obj, field_name) != val: | |
| setattr(obj, field_name, val) | |
| dirty = True | |
| if dirty: | |
| obj.save() | |
| else: | |
| obj = super(YourSerializer, self).from_native(data, files) | |
| return obj |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment