I am trying to install django-filer
and after following the installation docs(pip install, add to INSTALLED_APPS
etc), when I try run my dev server I get the following error in the terminal...
ERRORS:
<class 'filer.admin.folderadmin.FolderAdmin'>: (admin.E039) An admin for model "CustomUser" has to be registered to be referenced by FolderAdmin.autocomplete_fields.
<class 'filer.admin.permissionadmin.PermissionAdmin'>: (admin.E039) An admin for model "CustomUser" has to be registered to be referenced by PermissionAdmin.autocomplete_fields.
As visible in the error output. I've extended the Django user model with CustomUser
. I have also extended AdminSite
to get custom urls in the admin. So perhaps extending these is causing the error. Any possible solution to this?
The error says an admin has to be registered
and I do have multiple superusers registered.
This error is occurring because the filer app is trying to use the CustomUser model in its admin interface, but it is not able to find a registered admin for that model. To fix this, you will need to create an admin class for your CustomUser model that is compatible with the filer app.
You can do this by subclassing filer.admin.permissionadmin.PermissionAdmin or filer.admin.folderadmin.FolderAdmin instead of the default admin.ModelAdmin class, and then registering your custom admin class with the CustomUser model.
For example, you can create a file named admin.py in your app directory and add the following code:
from django.contrib import admin
from filer.admin.folderadmin import FolderAdmin
from myapp.models import CustomUser
class CustomUserAdmin(FolderAdmin):
pass
admin.site.unregister(CustomUser)
admin.site.register(CustomUser, CustomUserAdmin)
This code is creating a custom admin class CustomUserAdmin that inherits from filer.admin.folderadmin.FolderAdmin and then registering it to the CustomUser model using the admin.site.register() method.
You should also be aware that subclassing filer.admin.folderadmin.FolderAdmin also requires subclassing filer.admin.permissionadmin.PermissionAdmin, so you may need to create another custom admin class that inherit from filer.admin.permissionadmin.PermissionAdmin and register it to CustomUser as well.
Here is the code after update:
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from filer.admin.folderadmin import FolderAdmin
from myapp.models import CustomUser
class CustomUserAdmin(UserAdmin, FolderAdmin):
pass
admin.site.unregister(CustomUser)
admin.site.register(CustomUser, CustomUserAdmin)
This code creates a custom admin class CustomUserAdmin that inherits from both UserAdmin and FolderAdmin and then register it to CustomUser model.
You may also need to do the same thing with PermissionAdmin if you experience any issues
admin.py
were I inherit from from django.contrib.auth.admin import UserAdmin
. It complains if I try inherit from FolderAdmin
also. I need to look into inheriting from multiple classes now. Thanks a lot for your answer, really appreciate it.