有谁知道或可以请提供一个简单的Django基于类的通用DeleteView示例吗?我想继承DeleteView的子类,并确保当前登录的用户在删除对象之前拥有该对象的所有权。任何帮助将不胜感激。先感谢你。
这是一个简单的例子:
from django.views.generic import DeleteView from django.http import Http404 class MyDeleteView(DeleteView): def get_object(self, queryset=None): """ Hook to ensure object is owned by request.user. """ obj = super(MyDeleteView, self).get_object() if not obj.owner == self.request.user: raise Http404 return obj
注意事项:
DeleteView
GET
template_name
POST
delete
get_object
success_url