So i'm working on an inventory app, a django-app where you can handle inventory in a company. I've been using mostly class-based so far in my views.py
, and i can already create and edit all of my models using class-based views.
So when it comes to the generic.DeleteView
, i have some problems.
This is my function in views.py
:
class DeleteItemView(DeleteView):
model: Item
success_url: reverse_lazy('inventory_app:items')
template_name = 'inventory/detail_pages/item_detail.html'
And this is my URL to the function:
path('items/<int:pk>/delete/', views.DeleteItemView.as_view(), name='delete_item')
When i call this url with a button, this error appears:
DeleteItemView is missing a QuerySet. Define DeleteItemView.model, DeleteItemView.queryset, or override DeleteItemView.get_queryset().
So i heard online that this appears when /<int:pk>/
is missing in the url. But i have it in mine, so whats the problem here?
Thank you already
CodePudding user response:
class DeleteItemView(DeleteView): model = Item success_url = reverse_lazy('inventory_app:items') template_name = 'inventory/detail_pages/item_detail.html'
remove the colon (:)
and change to =