gmiza amel
gmiza amel

Reputation: 23

ImproperlyConfigured at /post/129/delete/ PostDeleteView is missing a QuerySet

i want to delete my project in my interface django with api but i received this problem ,please where is my error in this code ?

views.py

class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

def test_func(self,  *args, **kwargs):
   
    success_url = '/project/'
    headers = {'Content-type': 'application/json', 'PRIVATE-TOKEN': ''}
    pk = self.kwargs.get('pk')
    url="http://172.16.0.111/api/v4/projects/:id/"
    data={"name":"", "description":""}
    data=JsonResponse(data)
    headers = {'Content-type': 'application/json', 'PRIVATE-TOKEN': ''}
    response = requests.delete("http://172.16.0.111/api/v4/projects/:id/", 
    headers=headers,data=data)
  
    print(response)
    return HttpResponseRedirect(success_url)
    return Response(status = status.HTTP_204_NO_CONTENT)


   

Upvotes: 0

Views: 266

Answers (1)

Brainiac Rawkib
Brainiac Rawkib

Reputation: 41

Try to tweak your code like this, i hope it helps.

class PostDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
    model = Post
    extra_context = {'title': 'Delete Post'}
    success_url = '/blog/posts'
    template_name = 'blog/post_delete.html'

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

Upvotes: 1

Related Questions