views.py
from django.views.generic import DetailView, DeleteView
from .models import Post
class deletpost(DeleteView):
model = Post
success_url = '/'
def test_func(self):
post = self.get_object()
if self.request.user == post.author:
return True
return False
urls.py
from django.urls import path
from . import views
urlpatterns = [
path('post/<int:pk>/delete',views.deletpost.as_view(),name='delete-post')
]
create html go by name post_confirm_delete.html
{% block content %}
<form method="POST">
{% csrf_token %}
<h1>Are you sure?</h1>
<button type="submit">Delete</button>
<a href="{% url 'home' %}">Cancel</a>
</form>
{% endblock %}
Top comments (0)