mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-09 08:00:52 +03:00
Note removal of 'save_object' and fail loudly if it exists
This commit is contained in:
parent
0f508c5821
commit
5e74f02d61
|
@ -84,6 +84,8 @@ The resulting API changes are further detailed below.
|
||||||
|
|
||||||
The `.restore_object()` method is now replaced with two separate methods, `.create()` and `.update()`.
|
The `.restore_object()` method is now replaced with two separate methods, `.create()` and `.update()`.
|
||||||
|
|
||||||
|
These methods also replace the optional `.save_object()` method, which no longer exists.
|
||||||
|
|
||||||
When using the `.create()` and `.update()` methods you should both create *and save* the object instance. This is in contrast to the previous `.restore_object()` behavior that would instantiate the object but not save it.
|
When using the `.create()` and `.update()` methods you should both create *and save* the object instance. This is in contrast to the previous `.restore_object()` behavior that would instantiate the object but not save it.
|
||||||
|
|
||||||
The following example from the tutorial previously used `restore_object()` to handle both creating and updating object instances.
|
The following example from the tutorial previously used `restore_object()` to handle both creating and updating object instances.
|
||||||
|
|
|
@ -108,6 +108,13 @@ class BaseSerializer(Field):
|
||||||
raise NotImplementedError('`create()` must be implemented.')
|
raise NotImplementedError('`create()` must be implemented.')
|
||||||
|
|
||||||
def save(self, **kwargs):
|
def save(self, **kwargs):
|
||||||
|
assert not hasattr(self, 'save_object'), (
|
||||||
|
'Serializer `%s.%s` has old-style version 2 `.save_object()` '
|
||||||
|
'that is no longer compatible with REST framework 3. '
|
||||||
|
'Use the new-style `.create()` and `.update()` methods instead.' %
|
||||||
|
(self.__class__.__module__, self.__class__.__name__)
|
||||||
|
)
|
||||||
|
|
||||||
validated_data = dict(
|
validated_data = dict(
|
||||||
list(self.validated_data.items()) +
|
list(self.validated_data.items()) +
|
||||||
list(kwargs.items())
|
list(kwargs.items())
|
||||||
|
|
Loading…
Reference in New Issue
Block a user