我正在使用Django 1.6.5。基本上我想要的是,当用户点击“删除”时,链接,没有显示任何形式。只需更新*_deleted_at
字段,然后显示收件箱,而无需重定向到message_confirm_delete.html
模板。
鉴于以下内容:
urls.py
...
url(r'^delete/(?P<message_id>[\d]+)/$', delete, name='messages_delete'),
...
views.py
def delete(request, message_id, success_url=None):
user = request.user
now = timezone.now()
message = get_object_or_404(Message, id=message_id)
deleted = False
if success_url is None:
success_url = reverse('messages:messages_inbox')
if 'next' in request.GET:
success_url = request.GET['next']
if message.sender == user:
message.sender_deleted_at = now
deleted = True
if message.recipient == user:
message.recipient_deleted_at = now
deleted = True
if deleted:
message.save()
return HttpResponseRedirect(success_url)
raise Http404
如何将以下基于函数的视图转换为基于类的视图?不确定哪一个适合此处:UpdateView
或DeleteView
。
答案 0 :(得分:0)
您也可以针对此案例使用RedirectView
或使用DeletionMixin