博客五部曲之三 - 博客RESTful
1406 浏览 5 years, 9 months
7 UpdateView & DestroyView
版权声明: 转载请注明出处 http://www.codingsoho.com/UpdateView & DestroyView
实现跟DetailView非常类似
class PostUpdateAPIView(UpdateAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = "slug"
class PostDeleteAPIView(DestroyAPIView):
queryset = Post.objects.all()
serializer_class = PostDetailSerializer
lookup_field = "slug"
urlpatterns = [
url(r'^(?P<slug>[\w-]+)/edit$', PostUpdateAPIView.as_view(), name="update"),
url(r'^(?P<slug>[\w-]+)/delete$', PostDeleteAPIView.as_view(), name="delete"),
删除链接为http://127.0.0.1:8000/api/posts/new-post/delete,本身它不会删除对象,因为执行的是GET操作,Delete可以通过上面的Delete按钮操作