Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's current Django for "from django.views.generic import list_detail"?

Tags:

python

django

Am I correct in understanding that "from django.views.generic import list_detail" has been deprecated and/or removed from Django?

If so, what is the appropriate successor?

Thanks,

--

@Gareth, thanks.

I have a followup question to ask: how do you use a ListView to replace a list_detail.object_detail?

The present code, which has been changed only in the import, is:

from django.conf.urls.defaults import *
#from django.views.generic import list_detail
from django.views.generic.list import ListView

from announcements.models import Announcement
from announcements.views import *


announcement_detail_info = {
    "queryset": Announcement.objects.all(),
}

urlpatterns = patterns("",
    url(r"^(?P<object_id>\d+)/$", list_detail.object_detail,
        announcement_detail_info, name="announcement_detail"),
    url(r"^(?P<object_id>\d+)/hide/$", announcement_hide,
        name="announcement_hide"),
    url(r"^$", announcement_list, name="announcement_home"),
)

https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-display/#listview does not seem to suggest a single inline replacement for:

    url(r"^(?P<object_id>\d+)/$", list_detail.object_detail,
        announcement_detail_info, name="announcement_detail"),

If anything, it suggests an additional model be added, and that model be built on.

Is there a quick, inline replacement for the list_detail.object_detail call, or does it take more uprooting?

Thanks,

like image 308
Christos Hayward Avatar asked Mar 25 '13 20:03

Christos Hayward


2 Answers

django.views.generic.list_detail was deprecated in Django 1.3:

From Django 1.3, function-based generic views have been deprecated in favor of a class-based approach.

Use django.views.generic.list.ListView instead.

like image 116
Gareth Rees Avatar answered Nov 14 '22 21:11

Gareth Rees


After importing django.views.generic.list.ListView

You just need to change list_detail.object_detail to ListView.as_view()

like image 34
Douglas Miranda Avatar answered Nov 14 '22 22:11

Douglas Miranda