django deleteview code example

Example 1: django deleteview class

##### views.py #####
from django.urls import reverse_lazy
from django.views.generic.edit import DeleteView
from myapp.models import Author

class AuthorDelete(DeleteView):
    model = Author
    success_url = reverse_lazy('author-list')
    
##### author_confirm_delete.html #####
<form method="post">{% csrf_token %}
    <p>Are you sure you want to delete "{{ object }}"?</p>
    <input type="submit" value="Confirm">
</form>

Example 2: django edit model data in django view

emp = Employee.objects.get(pk = emp_id)
emp.name = 'Somename'
emp.save()