#Admin site - Permissions denied

13 messages · Page 1 of 1 (latest)

analog orchid
#

Hello, I'm trying to override the default admin site to add some elements (basically menu items to custom pages).
I followed the latest documentation, and it seems to be working except that when accessing the administration I'm being told :
You don’t have permission to view or edit anything.
Which is weird because I still have the "LogEntry" block with my last actions. And I can see that I'm logged with the super-user account.
I've tried re-logging, but it doesn't help.

Below are the relevant lines of code I believe.

# project/admin.py
class CustomAdminSite(admin.AdminSite):
  site_header = 'Ascension - Administration'  # Customize the header text
  site_title = 'Ascension - Administration'   # Customize the browser tab title
  index_title = 'Game administration'

custom_admin_site = CustomAdminSite()

# project/apps.py
from django.contrib.admin import apps

class CustomAdminConfig(apps.AdminConfig):
  default_site = "admin.CustomAdminSite"

# project/urls.py
from admin import CustomAdminSite
custom_admin_site = CustomAdminSite()

urlpatterns = [
    path('', RedirectView.as_view(url='/admin')),
    path('admin', custom_admin_site.urls),
    # path('admin', admin.site.urls),
] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)

# project/settings.py
INSTALLED_APPS = [
  'ascension',
  'apps.CustomAdminConfig',
 # 'django.contrib.admin',
  'django.contrib.auth',
  'django.contrib.contenttypes',
  'django.contrib.sessions',
  'django.contrib.messages',
  'django.contrib.staticfiles',
]

If anything more is needed please let me know.
Thank you for your time.

analog orchid
#

something weird is that whatever I put in AdminConfig :

# project/apps.py
from django.contrib.admin import apps

class CustomAdminConfig(apps.AdminConfig):
  # default_site = "admin.CustomAdminSite"
  default_site = "django.contrib.admin.sites.AdminSite"```
The administration always uses my CustomAdminSite properties (site_header, site_title, index_title).
#

yes, so only the urls.py seems to matter, whatever the AdminConfig.default_site, it changes nothing.

worn pewter
#

Did you register your models via the custom admin site or via the default admin?

If you’d like to set up your own admin site with custom behavior, you’re free to subclass AdminSite and override or add anything you like. Then, create an instance of your AdminSite subclass (the same way you’d instantiate any other Python class) and register your models and ModelAdmin subclasses with it instead of with the default site. Finally, update myproject/urls.py to reference your AdminSite subclass.

https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#customizing-the-adminsite-class

analog orchid
#

yes I did.
Though I was tired of trying to debug, so I made a new django project from scratch and there it works fine.
I guess I'll just copy and paste all my code in there and be done with it. 🙂

worn pewter
#

That's the best way to solve a problem, well done.

If you manage to pinpoint what was wrong, I'd like to know.

soft abyss
#

Are you using an admin user or a regular staff user? Admins tend to have permission for everything, whereas staff needs to be configured.

analog orchid
#

I think it's related to my project architecture, I didn't use the start app and created the app folder manually.

#

i'm using the super user

soft abyss
#

That's... odd

soft abyss
analog orchid
#

it's not on github no, I could give you a zip though, I barely have anything done.
But really it's probably a waste of time, I've got it working by starting a new project, I'll just copy the few lines of code I have in there and forget about this.
This thing wasted me 4h already, I'll just move ahead next time I get to coding