The django.views.generic.create_update.delete_object view renders a generic view that displays a form for deleting objects. The delete_object view requires a model, an object_id, and a post_delete_redirect object. The view retrieves the object and uses it to create a Form object that is passed to the template in the context variable form.
The form is displayed if it is accessed with a GET request, and the object is deleted on a POST request.
The required arguments are model, object_id, and post_delete_redirect.
The optional arguments are login_required, template_name, template_loader, extra_context, and context_processors.
The context variables are object and extra_context.
The default template_name is app_label/model_name_form.html (such as People/Person_form.html).
The following code snippet shows an example of defining a generic update_object view in the URLconf file:
blog_info = { 'model' : Blog, 'post_delete_redirect' : '/blog/list', } urlpatterns += patterns('', (r'^generic/blog_delete/(?P<object_id>\d+)/$', }
The following template code snippet shows an example of accessing the context variable object in a deletion template to display the Blog object being deleted:
<form action="" method="post"> <p>{{ object.title }}</p> <p> -{{ object.text }}</p> <input type="submit" /> </form>
Try It Yourself: Use a Generic View to Implement an Object Deletion FormIn this section you will use the delete_object generic view to display a Quote object deletion form that deletes Quote objects. Follow these steps to create a template and update the URLconf file to enable the view:
|