I'm working through the book with the alpha 2 release of django and
the way I got this to work was to copy the FlatPageAdmin from
django.contrib.flatpages.admin and add the inlines field to it. I
added an import for FlatpageForm rather than copying that also.
Its strange that the 'p' in FlatpageForm isn't capitalized like the
other FlatPage classes.
from django.db import models
from django.contrib.flatpages.models import FlatPage
from django.contrib.flatpages.admin import FlatpageForm
from django.utils.translation import ugettext_lazy as _
class SearchKeyword(models.Model):
keyword = models.CharField(max_length=50, core=True)
page = models.ForeignKey(FlatPage, edit_inline=models.STACKED,
min_num_in_admin=3, num_extra_on_change=1)
def __unicode__(self):
return self.keyword
from django.contrib import admin
class SearchKeywordAdmin(admin.StackedInline):
model = SearchKeyword
extra = 3
class FlatPageAdmin(admin.ModelAdmin):
form = FlatpageForm
fieldsets = (
(None, {'fields': ('url', 'title', 'content', 'sites')}),
(_('Advanced options'), {'classes': ('collapse',), 'fields':
('enable_comments', 'registration_required', 'template_name')}),
)
list_display = ('url', 'title')
list_filter = ('sites', 'enable_comments', 'registration_required')
search_fields = ('url', 'title')
inlines = [SearchKeywordAdmin]
admin.site.unregister(FlatPage)
admin.site.register(FlatPage, FlatPageAdmin)
On Jul 22, 1:51 am, eka <
ekagauranga...@gmail.com> wrote:
> I cleaned my code and found out that the solution seems to be:
>
> from django.contrib import admin
> from django.contrib.flatpages.models importFlatPage
> from django.contrib.flatpages.admin import FlatPageAdmin
> from cms.search.models import SearchKeyword
>
> class SearchKeywordInline(admin.StackedInline):
> model = SearchKeyword
> max_num = 1
> extra = 1
>
> class MyFlatPageAdmin(FlatPageAdmin):
> inlines = [
> SearchKeywordInline,
> ]
>
> admin.site.unregister(FlatPage)
> admin.site.register(FlatPage, MyFlatPageAdmin)
>
> and everything works great except for the extra option... but too late
> for me now, got to go to sleep.
>
> Thanks oebfare for the webcast ->
http://oebfare.com/blog/2008/jul/20/newforms-admin-migration-and-scre...