- class Publisher(models.Model):
- name = models.CharField(max_length=30)
- address = models.CharField(max_length=50)
- city = models.CharField(max_length=60)
- state_province = models.CharField(max_length=30)
- country = models.CharField(max_length=50)
- website = models.URLField()
- def __unicode__(self):
- return self.name
- class Meta:
- ordering = ['name']
- 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(),
- }
- urlpatterns = patterns('',
- (r'^publishers/$', list_detail.object_list, publisher_info)
- )
- 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)
- )
- {% extends "base.html" %}
- {% block content %}
- <h2>Publishers</h2>
- <ul>
- {% for publisher in object_list %}
- <li>{{ publisher.name }}</li>
- {% endfor %}
- </ul>
- {% endblock %}
新闻热点
疑难解答