Customizing the feincms page admin based on user
Asked Answered
M

2

6

I'm trying to find a way to filter the admin queryset for page objects based up on the user provided, what I've considered (pseudo code):

from feincms... Page

class MyPageAdmin(PageAdmin):
    def __init__(self, *args, **kwargs):
        'monkey business'
        super(MyPageAdmin, self).__init__(*args, **kwargs)

admin.site.unregister(Page)
admin.site.register(Page, MyPageAdmin)

This won't work because feincms checks for a completely loaded django instance. A verbose solution would probably be not to load the page module at all, and either override the page model object or admin, e.g.:

from feincms... PageAdmin

class MyPage(Page):
    objects = CustomManager()

admin.site.register(MyPage, PageAdmin)

The documentation states it is possible to setup your own page module in a similar way, but it seems a lot of configuration for a simple requirement.

Is there any easier way to override the admin queryset or model admin for feincms modules?

Maidenhood answered 9/2, 2013 at 13:6 Comment(2)
Shouldn't overriding the queryset method of the standard PageAdmin work?Fazio
@arie, yes but not in the conventional way, I just figured out how to patch them correctly.Maidenhood
E
6

FeinCMS v1.7 also allows you to set FEINCMS_USE_PAGE_ADMIN=False in your Django settings.

Then, just subclass PageAdmin as you normally would, and register the model admin with the model yourself.

You should also start importing PageAdmin from feincms.module.page.modeladmins if you're using v1.7.

Epizootic answered 19/3, 2013 at 8:27 Comment(0)
M
3

The trick here is you cannot unregister the feincms modules because of some magic performed. Instead of registering your own feincms Page object, you can patch the methods like this:

from django.conf import settings
from feincms.module.page.models import PageAdmin

def queryset(self, request):
    qs = super(PageAdmin, self).queryset(request)
    if request.user.is_superuser:
        return qs
    return qs.filter(site__id__exact=settings.SITE_ID)
PageAdmin.queryset = queryset
Maidenhood answered 9/2, 2013 at 14:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.