I read several textbooks and books about general ideas .
In part 4 of the official textbook , they wrote an example like this
from django.conf.urls import patterns, include, url from django.views.generic import DetailView, ListView from polls.models import Poll urlpatterns = patterns('', url(r'^$', ListView.as_view( queryset=Poll.objects.order_by('-pub_date')[:5], context_object_name='latest_poll_list', template_name='polls/index.html')), url(r'^(?P<pk>\d+)/$', DetailView.as_view( model=Poll, template_name='polls/detail.html')), url(r'^(?P<pk>\d+)/results/$', DetailView.as_view( model=Poll, template_name='polls/results.html'), name='poll_results'), url(r'^(?P<poll_id>\d+)/vote/$', 'polls.views.vote'), )
I also read Django Ultimate Guide: Web Development Done Right, Second Edition , and when they talked about general concepts, they wrote their example as follows
from django.conf.urls.defaults import * from django.views.generic import list_detail from mysite.books.models import Publisher publisher_info = { 'queryset': Publisher.objects.all(), 'template_name': 'publisher_list_page.html', } urlpatterns = patterns('', (r'^publishers/$', list_detail.object_list, publisher_info) )
Should I use ListView
or list_detail
? Both come from django.views.generic
. If both of them can be used, then what is the difference (advantage and disadvantage of comparison)?
In case this helps, I will explain my purpose: in my project I want to list the work orders, and then I want to get a detailed view of each work order, which will also have a list of comments for this order (similar to the comments on the message in blog).