Customize Page or PageAdmin

73 views
Skip to first unread message

Robert Slotboom

unread,
Sep 10, 2014, 8:47:01 AM9/10/14
to django-...@googlegroups.com
Hi guys,

For one of my projects I definitely need to change the look for the page admin.
The point is that some fields from page extensions should move up from the tabs to a new fieldset underneath the first fieldset (the one with active, title, slug...)   

I tried to customize the admin (seo extention as an example)

from feincms.module.page.models import Page
from feincms.module.page.modeladmins import PageAdmin as OrigPageAdmin
from feincms.admin import item_editor

class PageAdmin(OrigPageAdmin):

    fieldsets = [
(None, {
'fields': [('active', 'in_navigation'), ('title', 'slug')],
}),
('Metadata', {
'fields': ['meta_keywords', 'meta_description',],
}),
(_('Other options'), {
'classes': ['collapse'],
'fields': [
'template_key', 'parent', 'override_url', 'redirect_to'],
}),
        # <-- insertion point, extensions appear here, see insertion_index
        # above
        item_editor.FEINCMS_CONTENT_FIELDSET,
    ]

admin.site.register(Page, PageAdmin)

But that leads to a fieldset containing the correct fields + a tab with the same fields.

Is it possible at all to customize things this way?


Best regards,

Rob


 

Matthias Kestenholz

unread,
Sep 10, 2014, 10:24:23 AM9/10/14
to FeinCMS
Hi Rob


If you modify the page admin this way, I suggest you also add the SEO extension to your own project, and remove the `modeladmin.add_extension_options` part.



This also means that you have to pass your own extension instead of 'feincms.module.extension.seo' to register_extensions.

I hope this is helpful.

Best regards,
Matthias


Robert Slotboom

unread,
Sep 10, 2014, 11:06:38 AM9/10/14
to django-...@googlegroups.com


If you modify the page admin this way, I suggest you also add the SEO extension to your own project, and remove the `modeladmin.add_extension_options` part.



This also means that you have to pass your own extension instead of 'feincms.module.extension.seo' to register_extensions.

I hope this is helpful.

Best regards,
Matthias



Hi Matthias,

Yes very helpfull, thanks.
A was afraid I had to define a custom Page Model....

Ze code.


settings
FEINCMS_USE_PAGE_ADMIN=False

SOUTH_MIGRATION_MODULES = {
}



models
Page.register_extensions(
'website.cms_extensions.page.seo',
'feincms.module.page.extensions.navigation',
)


custom extensions
class Extension(extensions.Extension):
    def handle_model(self):
        self.model.add_to_class('meta_keywords', models.TextField(
            _('meta keywords'),
            blank=True,
            help_text=_('Keywords are ignored by most search engines.')))
        self.model.add_to_class('meta_description', models.TextField(
            _('meta description'),
            blank=True,
            help_text=_('This text is displayed on the search results page. '
                        'It is however not used for the SEO ranking. '
                        'Text longer than 140 characters is truncated.')))

    def handle_modeladmin(self, modeladmin):
        modeladmin.extend_list(
            'search_fields',
            ['meta_keywords', 'meta_description'],
        )


custom admin
...
from feincms.module.page.models import Page

Robert Slotboom

unread,
Sep 10, 2014, 11:18:55 AM9/10/14
to django-...@googlegroups.com
Hi Matthias,

And after revisiting the admin page, it does not work anymore :-( Fieldset gone, tab returned...

Robert Slotboom

unread,
Sep 10, 2014, 11:27:16 AM9/10/14
to django-...@googlegroups.com


On Wednesday, September 10, 2014 5:18:55 PM UTC+2, Robert Slotboom wrote:
Hi Matthias,

And after revisiting the admin page, it does not work anymore :-( Fieldset gone, tab returned...

FIX

I added 'classes': ['collapse'].
Removing this solved the question.

Reply all
Reply to author
Forward
0 new messages