然后
报错:
NotImplementedError at /shopcarts/1/
`update()` must be implemented.
Request Method: PUT
Request URL: http://127.0.0.1:8000/shopcarts/1/
Django Version: 1.11.6
Exception Type: NotImplementedError
Exception Value:
`update()` must be implemented.
Exception Location: D:\Envs\MxShop\lib\site-packages\rest_framework\serializers.py in update, line 166
Python Executable: D:\Envs\MxShop\Scripts\python.exe
Python Version: 3.6.0
Python Path:
['C:\\Users\\huang\\PycharmProjects\\MxShop\\extra_apps',
'C:\\Users\\huang\\PycharmProjects\\MxShop\\apps',
'C:\\Users\\huang\\PycharmProjects\\MxShop',
'C:\\Users\\huang\\PycharmProjects\\MxShop',
'C:\\Program Files\\JetBrains\\PyCharm 2018.2.4\\helpers\\pydev',
'C:\\Users\\huang\\PycharmProjects\\MxShop',
'C:\\Users\\huang\\PycharmProjects\\MxShop\\apps',
'C:\\Users\\huang\\PycharmProjects\\MxShop\\extra_apps',
'C:\\Program Files\\JetBrains\\PyCharm 2018.2.4\\helpers\\pydev',
'C:\\Users\\huang\\.PyCharm2018.2\\system\\cythonExtensions',
'D:\\Envs\\MxShop\\Scripts\\python36.zip',
'C:\\Users\\huang\\AppData\\Local\\Programs\\Python\\Python36\\DLLs',
'C:\\Users\\huang\\AppData\\Local\\Programs\\Python\\Python36\\lib',
'C:\\Users\\huang\\AppData\\Local\\Programs\\Python\\Python36',
'D:\\Envs\\MxShop',
'D:\\Envs\\MxShop\\lib\\site-packages',
'D:\\Envs\\MxShop\\lib\\site-packages\\setuptools-39.1.0-py3.6.egg',
'C:\\Program Files\\JetBrains\\PyCharm '
'2018.2.4\\helpers\\pycharm_matplotlib_backend']
Server time: 星期六, 11 五月 2019 19:03:36 +0800
解决办法:
def update(self, instance, validated_data):
# 修改商品数量
instance.nums = validated_data["nums"]
instance.save()
return instance
再 put一次 修改成功
删除功能也能实现