tags:

views:

45

answers:

2

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 wrong, 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?

+1  A: 

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?

Manoj Govindan
I'm running Lucid, with the versions of django and Python that the repositories provided me with. I've not checked the versions.I posted this before I left for work, I'll not be able to get back to it until this evening.When I do, I'll check the versions. It may be that I got a 1.0 version of django, if so, I'll see about pulling down the most current.If that isn't it, I'll download the code from the two sites mentioned above, and try each. If one or the other works, I'll then diff against my code, to see if I can identify what I was doing wrong.Thanks.
Jeff Dege
+1  A: 

Your code looks healthy to me, so something you've not posted is wrong.

Are you importing everything required?

  • Your models.py needs django.db.models and FlatPage (presumably from django.contrib.flatpages.FlatPage)
  • Your admin.py needs from django.contrib import admin and from cms.search.models import SearchKeyword

Is cms.search in your INSTALLED_APPS setting?

Dominic Rodger