"Practical django Projects, 2nd ed., source code
In James Bennett's "Practical django Projects" (2nd edition) the author builds a content management system, leveraging off of django.contrib.admin. The problem is that it doesn't work.
I'm in chapter three, where he adds a keyword search capability, by adding a new admin module. The problem is is that I can't get it to work. Browsing around the web, I find constant complaints that despite the claims in the book, the author has not made working source available. The core of the problem is that he seems to be depending upon internals of the django platform that are changing with every minor release, hence his solutions prove fragile.
Still, I'd like to work my way through this.
In chapter three, he supposedly adds a new search keyword admin function, by creating a new SearchKeyword model, and then creating and registering a SearchKeywordAdmin class.
The model (in cms/search/models.py:
class SearchKeyword(models.Model):
keyword = models.CharField(max_length=50)
page = models.ForeignKey(FlatPage)
def __unicode__(self):
return self.keyword
The class (in cms/search/admin.py):
class SearchKeywordAdmin(admin.ModelAdmin):
pass
admin.site.register(SearchKeyword, SearchKeywordAdmin)
I see no compile errors, but I see nothing on the admin page.
Either I'm doing something w开发者_运维知识库rong, or something in django.contrib.admin has changed, to make this code no longer work.
Anyone have any ideas which? And what I might need to do to make this work?
Your code looks healthy to me, so something you've not posted is wrong.
Are you importing everything required?
- Your
models.py
needsdjango.db.models
andFlatPage
(presumably fromdjango.contrib.flatpages.FlatPage
) - Your
admin.py
needsfrom django.contrib import admin
andfrom cms.search.models import SearchKeyword
Is cms.search
in your INSTALLED_APPS
setting?
I tried your code with Django 1.2.1 and Python 2.6.2 on Ubuntu Jaunty. The model showed up in the admin screen as expected. Can you post more details about the version of Django/Python you are using?
Do you have:
from django.contrib import admin
admin.autodiscover()
in your urls.py
? And also something like this:
urlpatterns = patterns('',
...
(r'^admin/', include(admin.site.urls)),
)
And also have you turned on admin app in settings?
INSTALLED_APPS = (
...
'django.contrib.admin',
)
You may need to simply run manage.py runserver
again to allow the admin section to reset.
精彩评论