I have few models in my Django app. How do I imitate another app to create app section for one of my models in admin interface?
Asked
Active
Viewed 664 times
1
-
2what did you mean by imitating? – doubleo46 Jul 18 '18 at 07:15
-
1When you create new app and register models in it, you see new section for this app in admin panel. I want to make new section without creating new app – Dmitry Sazhnev Jul 18 '18 at 07:20
-
Register your models with admin.site.register(your model). https://docs.djangoproject.com/en/2.0/ref/contrib/admin/#modeladmin-objects – doubleo46 Jul 18 '18 at 07:29
2 Answers
2
The AdminSite is responsible for creating the index page. The process is as such:
_build_app_dict
builds a dictionary containing various data (including model._meta.app_label) of all models registered with the given siteget_app_list
turns that dictionary into a list sorted by app label and by model (verbose) name- the
index
method/view adds that app_list to the template context - the template (specified by AdminSite.index_template) is rendered
If all you want to do, is alter the appearance of the index page (say by adding a 'fake' app to group your models differently), creating a custom AdminSite and hooking into any of the four steps above might be a cleaner way than messing with the internal app registry.

CoffeeBasedLifeform
- 2,296
- 12
- 27
1
You can try changing the app_label
of your models you want to move:
class Meta:
app_label = 'new_section'
Just make sure to adapt the FK and M2M fields accordingly.
See this answer.

Cyrlop
- 1,894
- 1
- 17
- 31