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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With