20121022 django学习笔记2

INSTALLED_APPS  'django.contrib.admin' #settings.py添加

mysite/urls.py #定义url

 1 from django.conf.urls.defaults import *
 2 
 3 # Uncomment the next two lines to enable the admin:
 4 from django.contrib import admin
 5 admin.autodiscover()
 6 
 7 urlpatterns = patterns('',
 8     # Example:
 9     # (r'^mysite/', include('mysite.foo.urls')),
10 
11     # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
12     # to INSTALLED_APPS to enable admin documentation:
13     # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
14 
15     # Uncomment the next line to enable the admin:
16     (r'^admin/', include(admin.site.urls)),
17 )

python manage.py runserver #启动工程
http://127.0.0.1:8000/admin/

polls/admin.py

 1 from polls.models import Poll
 2 from django.contrib import admin
 3 
 4 class ChoiceInline(admin.TabularInline):
 5     model = Choice
 6     extra = 3
 7 
 8 class PollAdmin(admin.ModelAdmin):
 9     fieldsets = [
10         (None,               {'fields': ['question']}),
11         ('Date information', {'fields': ['pub_date'], 'classes': ['collapse']}),
12     ]
13     inlines = [ChoiceInline]
14 
15     list_display = ('question', 'pub_date')
16     list_display = ('question', 'pub_date', 'was_published_today')
17     list_filter = ['pub_date']
18     search_fields = ['question']
19     date_hierarchy = 'pub_date'
20 
21 admin.site.register(Poll, PollAdmin)
posted @ 2012-10-23 10:17  zhu327  阅读(173)  评论(0)    收藏  举报