To delete an object I inherit from DeleteView which has 3 steps (user clicks on delete, goes to confirm page, click yes again, redirected to success page) How can I make it more inline (user clicks delete, alert window pops up asking user to confirm, user confirms, the object is gone, user is still on the same page)
url(r'^(?P<username>\w+)/recipientbank/delete/(?P<pk>\d+)/$', RecipientBankAccountDeleteView.as_view(model=RecipientBankAccount)),
url(r'^(?P<username>\w+)/recipientbank/delete/(\d+)/success/$',recipientbank_deleted,name='recipientbank_deleted'),
class RecipientBankAccountDeleteView(Delet开发者_如何学JAVAeView):
form_class = RecipientBankAccountForm
success_url='success'
def delete(self, request, *args, **kwargs):
self.object = self.get_object()
self.object.delete()
return HttpResponseRedirect(self.get_success_url())
def recipientbank_deleted(request, username, public_profile_field=None,template_name='main/recipientbankaccount_deleted.html',extra_context=None):
return render(request, template_name)
You should use django-piston to create RESTful APIs and make an AJAX call from your page to delete your django objects.
You can read about RESTful here: http://en.wikipedia.org/wiki/Representational_State_Transfer
and django-piston here: https://bitbucket.org/jespern/django-piston/wiki/Home
I've heard that you could achieve this with Generic Views starting django version 1.3, but I haven't used it.
精彩评论