MCPcopy Index your code
hub / github.com/encode/django-rest-framework / save

Method save

rest_framework/serializers.py:748–777  ·  view source on GitHub ↗

Save and return a list of object instances.

(self, **kwargs)

Source from the content-addressed store, hash-verified

746 ]
747
748 def save(self, **kwargs):
749 """
750 Save and return a list of object instances.
751 """
752 # Guard against incorrect use of `serializer.save(commit=False)`
753 assert 'commit' not in kwargs, (
754 "'commit' is not a valid keyword argument to the 'save()' method. "
755 "If you need to access data before committing to the database then "
756 "inspect 'serializer.validated_data' instead. "
757 "You can also pass additional keyword arguments to 'save()' if you "
758 "need to set extra attributes on the saved model instance. "
759 "For example: 'serializer.save(owner=request.user)'.'"
760 )
761
762 validated_data = [
763 {**attrs, **kwargs} for attrs in self.validated_data
764 ]
765
766 if self.instance is not None:
767 self.instance = self.update(self.instance, validated_data)
768 assert self.instance is not None, (
769 '`update()` did not return an object instance.'
770 )
771 else:
772 self.instance = self.create(validated_data)
773 assert self.instance is not None, (
774 '`create()` did not return an object instance.'
775 )
776
777 return self.instance
778
779 def is_valid(self, *, raise_exception=False):
780 # This implementation is the same as the default,

Callers

nothing calls this directly

Calls 2

updateMethod · 0.95
createMethod · 0.95

Tested by

no test coverage detected