How to inline somethin to a FlatPage

77 views
Skip to first unread message

eka

unread,
Jul 21, 2008, 3:45:07 PM7/21/08
to Django users
Hi,

Im reading the book 'Practical Django Projects', and trying to make it
work with latest changes in Django SVN
I'm trying to use edit inline (this is very new to me) with FlatPages
and when I do the following

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

class SearchKeywordInline(admin.StackedInline):
model = SearchKeyword

class FlatPageAdmin(admin.ModelAdmin):
inline = [
SearchKeywordInline,
]


admin.site.register(FlatPage, FlatPageAdmin)

I get:

The model FlatPage is already registered.

I think that FlatPages have another way to inline edit things?

any help here appreciated...

slav0nic

unread,
Jul 21, 2008, 3:56:44 PM7/21/08
to Django users
try admin.site.unregister(FlatPage) befor register it

eka

unread,
Jul 21, 2008, 4:53:24 PM7/21/08
to Django users
Doesn't seem to work

On Jul 21, 4:56 pm, slav0nic <slav0n...@gmail.com> wrote:
> try admin.site.unregister(FlatPage) befor register it

eka

unread,
Jul 21, 2008, 5:18:38 PM7/21/08
to Django users
The problem is

class FlatPageAdmin(admin.ModelAdmin):
inline = [
SearchKeywordInline,
]

its inlines instead of inline...

but still i have to unregister and the register flatpages and that
breaks some other things


any better solution?

eka

unread,
Jul 21, 2008, 8:51:42 PM7/21/08
to Django users
I cleaned my code and found out that the solution seems to be:

from django.contrib import admin
from django.contrib.flatpages.models import FlatPage
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-screencast/

isteve

unread,
Aug 14, 2008, 3:27:33 PM8/14/08
to Django users
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...
Reply all
Reply to author
Forward
0 new messages