문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top