Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

improperly configured at /18/delete, Django views issue

I have searched through the other questions similar to my own problem and have come to no solution so im hoping someone can help me figure out where i went wrong.

I’m trying to implement a delete post option in my blog program but it is throwing the following error once you click the ‘delete’ button:

ImproperlyConfigured at /18/delete/
Deletepost is missing a QuerySet. Define Deletepost.model, Deletepost.queryset, or override Deletepost.get_queryset().

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am nearly sure its a problem with my URLS.py though what exactly i cannot figure out.

the following is the code in question:

Views.py

# delete post
class Deletepost(LoginRequiredMixin, DeleteView):
    form_class = Post
    success_url = reverse_lazy('blog:home')
    template_name = 'templates/post.html'

    def test_func(self):
        post = self.get_object()
        if self.request.user == post.author:
            return True
        return False

urls.py

urlpatterns = [
    # home
    path('', views.postslist.as_view(), name='home'),

    # add post
    path('blog_post/', views.PostCreateView.as_view(), name='blog_post'),

    # posts/comments
    path('<slug:slug>/', views.postdetail.as_view(), name='post_detail'),

    # edit post
    path('<slug:slug>/edit/', views.Editpost.as_view(), name='edit_post'),

    # delete post
    path('<int:pk>/delete/', views.Deletepost.as_view(), name='delete_post'),

    # likes
    path('like/<slug:slug>', views.PostLike.as_view(), name='post_like'),

]

post.html

<a class="btn btn-outline-danger" href="{% url 'delete_post' post.id %}">Delete</a>

Thanks for your time and i’m sorry for the trivial question but you guys are much smarter than me!

>Solution :

I think it should be model not form_class so:

class Deletepost(LoginRequiredMixin, DeleteView):
    model = Post
    success_url = reverse_lazy('blog:home')
    template_name = 'templates/post.html'

    def test_func(self):
        post = self.get_object()
        if self.request.user == post.author:
            return True
        return False
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading