Reputation: 33
I have single Django app and it contain 2 models Store and Account. I registered them in admin.py and I get them in the admin in one block "EXAMPLE APP"
Now I`d like to split it into two blocks to better UI:
"EXAMPLE APP" will contain only Account
"ANOTHER BLOCK WITH CUSTOM NAME" that will have Store model.
this looks like the current state
# admin.py
class FooAdminSite(AdminSite):
site_title = "Foo Admin"
site_header = 'Foo administration'
class AccountAdmin(admin.ModelAdmin):
pass
class StoreAdmin(admin.ModelAdmin):
pass
admin_site = FooAdminSite(name='admin')
admin_site.register(Account, AccountAdmin)
admin_site.register(Store, StoreAdmin)
# urls.py
from foo.admin import admin_site
urlpatterns = [
url(r'^admin/', admin_site.urls),
]
How I can achieve this to looks like on this screenshot
I don't want add another app - just want use single app and customize admin.
I tried add another AppConfig in apps.py but it didn`t help.
Upvotes: 3
Views: 2068
Reputation: 21
It can help you : django-modeladmin github's repository
# Keep original label and models
'sites',
# Rename app
{'app': 'auth', 'label': 'Authorisation'},
# Reorder app models
{'app': 'auth', 'models': ('auth.User', 'auth.Group')},
# Exclude models
{'app': 'auth', 'models': ('auth.User', )},
# Cross-linked models
{'app': 'auth', 'models': ('auth.User', 'sites.Site')},
# models with custom name
{'app': 'auth', 'models': (
'auth.Group',
{'model': 'auth.User', 'label': 'Staff'},
)},
Upvotes: 2
Reputation: 2507
The Django official documentation suggests to Customize the admin index page
[...] you might want to customize the look and feel of the Django admin index page. By default, it displays all the apps in INSTALLED_APPS that have been registered with the admin application, in alphabetical order. You may want to make significant changes to the layout. After all, the index is probably the most important page of the admin, and it should be easy to use. The template to customize is admin/index.html. (Do the same as with admin/base_site.html in the previous section – copy it from the default directory to your custom template directory). Edit the file, and you’ll see it uses a template variable called app_list. That variable contains every installed Django app. Instead of using that, you can hard-code links to object-specific admin pages in whatever way you think is best.
Upvotes: 0
Reputation: 2054
You will need to customize the AdminSite
class. As a starting point have a look at:
app_list
dict used to display this. django.contrib.admin.sites.AdminSite#get_app_listI would change the app_label
variable in django.contrib.admin.sites.AdminSite#_build_app_dict to something like:
app_label = getattr(model_admin, 'category', None) or model._meta.app_label
Then in your admin models you could do:
class StoreAdmin(admin.ModelAdmin):
category = 'ANOTHER BLOCK WITH CUSTOM NAME'
This will have some side effects and you will have to do more changes to your custom admin site to make this work, but I think this should give you the necessary info to begin.
Upvotes: 3