My IDE (PyCharm) keeps reporting: Function-based generic views have been deprecated.
I have the following statement in my import list:
from django.views.generic.list_detail import object_list
And my view looks like the following:
def category(request, id, slug=None):
category = Category.objects.get(pk=id)
books = Book.objects.filter(
Q(status = 1) & Q(category=category)
).order_by('-id')
s = Poet.objects.order_by('?')[:3]
return object_list(
request,
template_name = 'books/categories/show.html',
queryset = books,
paginate_by = 99,
extra_context = {
'category': category,
'suggestions': s,
'bucket_name': config.BOOKS_BUCKET_NAME,
}
)
I found this in SO, but the docs seems overly complicated in this regard.
Any tips on how I can convert my code would be appreciated.
You could try something like this
This code is not tested, please report back if it’s working for you.
Note that the book list will be available through the context variable ‘object_list’, if you want to give it a different name you can use the ‘context_object_name’ class member:
and in your urls.py use the class-based view’s as_view() method