Practical Django Projects. Page 36 Errata

For this post to make sense you should read this first.

First of all ignore the updated code on this page, and leave the search/models.py the way it looked before this page. Bellow is how it should look in case it helps:

from django.db import models
from django.contrib.flatpages.models import FlatPage

class SearchKeyword(models.Model):
	keyword = models.CharField(max_length=50)
	page = models.ForeignKey(FlatPage)
	def __unicode__(self):
		return self.keyword

Open up the admin.py file and change it so that it looks like this:

from cms.search.models import SearchKeyword
from django.contrib import admin
from django.contrib.flatpages.admin import FlatPageAdmin
from django.contrib.flatpages.models import FlatPage

class SearchKeywordInline(admin.StackedInline):
	model=SearchKeyword
	extra=3
FlatPageAdmin.inlines=[SearchKeywordInline]
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)

As you can see, now there classes for the different inline admin views(StackedInline and TabularInline) and all you need to do is create a new class that extends from one those for the model you want. One of the tricky things was to find out how to change the way the FlatPage model, which is a contributed app, is shown on the admin section. I believe the best way to do is to add the inline property to it and re-register the Admin Model of it so that the changes are picked up.

I would recommend you read this to get more familiar with the way the admin app works.

Leave a Reply