Django Admin的变化

今天从django的svn拉出一份出来写点东东,写好了models,runserver查看admin的时候却出现了如下提示

You don’t have permission to edit anything

翻了一下文档,发现已经0.97的时候变化了很多的东东。最后说明是要这样写。
urls.py里写入

from django.contrib import admin
admin.autodiscover()

settings.py中的INSTALLED_APPS部分加入

 INSTALLED_APPS = (
'django.contrib.admin')

models.py的最后要写上

from django.contrib import admin
admin.site.register(MODELNAME)

这样才算是OK。
update: django 1.0之后的应该把上面这一段放到admin.py里去,而且要把以前写在models.py里的class admin部分也放到admin.py例子如下:

from django.contrib import admin
from models import Module
class ModuleAdmin(admin.ModelAdmin):
list_display = ['name','manager','isdpool']
filter_horizontal = ['host']
admin.site.register(Module,ModuleAdmin)

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.