Dmitry Sazhnev
Dmitry Sazhnev

Reputation: 383

How to imitate new app in Django admin

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?

Upvotes: 2

Views: 987

Answers (2)

CoffeeBasedLifeform
CoffeeBasedLifeform

Reputation: 2921

The AdminSite is responsible for creating the index page. The process is as such:

  1. _build_app_dict builds a dictionary containing various data (including model._meta.app_label) of all models registered with the given site
  2. get_app_list turns that dictionary into a list sorted by app label and by model (verbose) name
  3. the index method/view adds that app_list to the template context
  4. 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.

Upvotes: 2

Cyrlop
Cyrlop

Reputation: 1984

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.

Upvotes: 1

Related Questions