Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Settings for multiple UnfoldAdminSites #768

Open
paulgueltekin opened this issue Sep 26, 2024 · 4 comments
Open

Settings for multiple UnfoldAdminSites #768

paulgueltekin opened this issue Sep 26, 2024 · 4 comments

Comments

@paulgueltekin
Copy link

Is it a third party application feature request?

No

Describe your feature request

Afaik there is currently no default way to use multiple UnfoldAdminSite instances with different settings:

`class TenantAdminSite(UnfoldAdminSite):
site_header = _("Tenant administration")

class SuperAdminSite(UnfoldAdminSite):
site_header = _("Super Administration")

admin_site = TenantAdminSite(name="tenantadmin")
super_admin_site = SuperAdminSite(name="superadmin")`

For example, using different sidebar configurations for each UnfoldAdminSite

My suggestion is to introduce a new optional setting "SITE_CONFIGS" eg

`"UNFOLD": {
"SIDEBAR": ... # default configuration
...
"SITE_CONFIGS": {
"SUPERADMIN": { "SIDEBAR": ..., # site specific configuration
"TABS: ... , },
"TENANTADMIN": { ... },
}

}`

In the UnfoldAdminSite, instead of calling get_config() directly, call a function that wraps the get_config() call thats tries to load from the optional site specific config first and if no such setting for the current AdminSite name is available, fall back to the default behaviour.

A point to discuss would be if all required settings should be defined in the site configuration. A other possible way would be site specific configuation would overlap the the default configuration, so common things can be configured in the default configuration, while certain options can be overidden in the site configuration.

I am not sure if this is too much of a border case as most projects just use one admin site but if there is interest i can provide a PR.

@lukasvinclav
Copy link
Contributor

lukasvinclav commented Sep 26, 2024

This is something what I was already playing with and right now there should be a partial support for this in Unfold:

https://github.com/unfoldadmin/django-unfold/blob/main/src/unfold/sites.py#L21

https://github.com/unfoldadmin/django-unfold/blob/main/src/unfold/settings.py#L57-L58

Anyway, this needs definitely more testing to polish edge cases and there are few things which will NOT work.

@Huanghibo
Copy link

Huanghibo commented Sep 27, 2024

I'm already stuck on this issue. For multiple UnfoldAdminSites , I always have "Reverse for 'app_model_changelist' not found." issues with my projects. In order to find out if my code is the reason, I re-created a test project, which only has two models, the user and the group of django. Strictly follow the official example, or this problem does not arise.

[Without the settings-UNFOLD setup and the multiple UnfoldAdminSites setup, the program runs normally.]

django 4.2.16
unfold 0.38/0.39
firefox 120.1

I follow this:

  1. https://unfoldadmin.com/docs/installation/

  2. https://unfoldadmin.com/docs/sites/
    【I'm also concerned with this note: If you use the default django.contrib.admin.AdminSite you will receive a NoReverseMatch error because the default admin site does not contain all URL patterns required by Unfold.】

  3. https://unfoldadmin.com/blog/migrating-django-admin-unfold/

The test project is as simple as creating a new Django project and importing Unfold. I wonder if I'm missing something, please guide. I need to migrate my project to Django unfold! Thank you so much!

1
2
3

@Huanghibo
Copy link

V0.39, There are new problems:
Admin user login:“You don’t have permission to view or edit anything. ”
6
5

@paulgueltekin
Copy link
Author

@lukasvinclav your approach seems to be simpler to implement with the multiple top level settings key instead of nested keys.

What things do you think will not work? Maybe we can define some tests.

I have currently my approach ( SITE_CONFIG in UNFOLD stting ) implemented in one of my projects and i havent entcountered any issues yet ( still not using every feature, just own SIDEBAR and TABs and custom pages for the admins )

@Huanghibo
i think because you register each UnfoldAdminSite with a own URL, having somewhere a reverse() in your code that is currently executed for every AdminSite as there is only one configuration ( eg a custom CALLBACK or a link in a TAB ) but the ModelAdmin is not registered on the current UnfoldAdminSite gives you this error. You could try @lukasvinclav setting to set a own configuration for the second UnfoldAdminSite.

for the second issue:
what happens if you remove the permission setting? I get the same error if i have no Admins registered in my AdminSite

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants