Opened 14 years ago

Closed 8 months ago

#7497 closed New feature (fixed)

AppAdmin class for customizing app listing in admin index

Reported by: mrts Owned by: Roman
Component: contrib.admin Version: dev
Severity: Normal Keywords:
Cc: Martin Mahner, ega641@…, Jannis Leidel, andy@…, sam.kuper@…, sehmaschine@…, Ben Davis, rh0dium, sebastian.goll@… Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

See http://code.djangoproject.com/wiki/DjangoSpecifications/NfAdmin/FlexibleAppHandling for details.

This supplements the app directive.

As discussed with brosner and jkocherhans in #django-dev:

<brosner> it looks reasonable, but haven't spent much time thinking about it
<jkocherhans> mrts: I think this is clearly backwards incompatible with the current nfa api and has to go in pre 1.0 if it goes in at all
<jkocherhans> I'm a big -1 on the order attribute and -0 on models (maybe just a different syntax), but the other stuff seems reasonable
<mrts> jkocherhans: what's wrong with ordering?
<jkocherhans> it just feels like the wrong place to specify it
<jkocherhans> it's a global issue, and an issue any particular app should handle
<mrts> my use case: I have a lot of functionality exposed to somewhat dumb users
<mrts> and they have trouble finding the right bits in the admin interface
 ordering is only used in context of admin index
 I would like to put the important apps to top and collapse the rest
<jkocherhans> exactly. what should 3rd party apps put there? therein lies my objection.
<mrts> well, I'd say decouple admin from models (as nfa already does) and don't specify any admin options at all -- users are free to customize things with AppAdmin
<jkocherhans> I guess not if using a AppAdmin class is optional. I was originally thinking it would replace model registration with an admin site.
<mrts> jkocherhans: yeah, that's what I kinda meant... it looks more coherent this way
 jkocherhans: and it may solve some of the issues register() currently has
<jkocherhans> mrts: I'm gonna have to let it sit for awhile. I'm trying to think of what else an AdminApp class would do besides being a coathanger for a few attributes, nothing is coming to mind.
<mrts> jkocherhans: but jezdez has a point -- it would also provide easy bridging for app instances

Example syntax follows.

class BarModelAdmin(admin.ModelAdmin):
   description = 'A bar is a bar is a bar'
   ...

class FooAppAdmin(admin.AppAdmin):
    app = settings.INSTALLED_APPS[0]
    name = "Foo" # overrides app().name
    description = "An application that does foo"
    style = {'classes' : ('collapse',)}
    order = 1
    models = ( # model order in this list determines their display order in app block
      (BarModel, BarModelAdmin),
      (BazModel, None), # use default ModelAdmin, don't show description
   )

admin.site.register(FooAppAdmin) # no need for the tedious for model in [A, B, C, D]: admin.site.register(model)

Change History (26)

comment:1 Changed 14 years ago by Jacob

milestone: 1.0post-1.0
Triage Stage: UnreviewedSomeday/Maybe

comment:2 Changed 14 years ago by mrts

app = settings.INSTALLED_APPS[0] is actually useless in the example.

comment:3 Changed 14 years ago by Martin Mahner

Cc: Martin Mahner added

comment:4 Changed 14 years ago by sorl

Can't we just add a label attribute to the ModelAdmin class? ModelAdmin classes with same label would group, possibly also position attribute.

comment:5 Changed 14 years ago by sorl

Im just thinking that the application grouping might not have much to do with how an administrator uses the admin tool.

comment:6 Changed 14 years ago by anonymous

Cc: ega641@… added

comment:7 Changed 14 years ago by sorl

What do you think of something like an optional layout?:

admin.site.layout = (
    (_("don't touch this stuff"), {
        'models': ('',
            'django.contrib.sites.models.Site',
        )
    }),
    (_('users & groups'), {
        'models': ('django.contrib.auth.models',
            'User', 'Group'
        )
    }),
    (_('pages & news'), {
        'models': ('',
            'example_project.pages.models.Page',
            'example_project.news.models.News',
        )
    }),
)

Also adding a description attribute to ModelAdmin.
You can see and read further on this idea and look at the implementation in my project sorl-curator

comment:8 Changed 14 years ago by Jannis Leidel

Cc: Jannis Leidel added

comment:9 Changed 14 years ago by Andy Baker

Cc: andy@… added

comment:10 Changed 14 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:11 Changed 14 years ago by phaesler

A somewhat related point - if you have two applications with the same basename in the one project, the admin application displays them as if they were merged into a single application with that name.

E.g. If 'foo.bar.myapp' and 'spam.eggs.myapp' are both in the INSTALLED_APPS list, and both have an admin.py; then admin displays them both as a single merged 'myapp' application.

comment:12 Changed 13 years ago by Russell Keith-Magee

#11895 proposed a similar idea, and provided a patch (which could also be implemented using subclassing).

comment:13 Changed 13 years ago by sampablokuper

Cc: sam.kuper@… added

Added CC.

comment:14 Changed 12 years ago by anonymous

Cc: sehmaschine@… added

comment:15 Changed 12 years ago by Luke Plant

Severity: Normal
Type: New feature

comment:16 Changed 11 years ago by Ben Davis

Cc: Ben Davis added
Easy pickings: unset
UI/UX: unset

comment:17 Changed 11 years ago by rh0dium

Cc: rh0dium added

comment:18 Changed 11 years ago by Sebastian Goll

Cc: sebastian.goll@… added

comment:19 Changed 10 years ago by Aymeric Augustin

Resolution: duplicate
Status: newclosed
Triage Stage: Someday/MaybeAccepted

This is #3591 — also known as the 'app-loading' branch.

comment:20 Changed 9 years ago by Aymeric Augustin

Resolution: duplicate
Status: closednew

Mmm, in fact this was specifically split from app-loading. Sorry.

comment:21 Changed 3 years ago by Evgeny Tatarintsev

Hi, I implemented apps ordering via "position" attribute in AppConfig class

class TestConfig(AppConfig):
    name = 'test'
    verbose_name = 'Test App'
    position = 0

Apps orders by it's "position" and then by "verbose_name", no backwards incompatible, if position not set just ordering by name.

If it's actual I can do pull request.

comment:22 Changed 9 months ago by Roman

To move things a little bit forward I have prepared a pull request based on this comment
https://code.djangoproject.com/ticket/25671#comment:11

https://github.com/django/django/pull/15483

comment:23 Changed 9 months ago by Mariusz Felisiak

Has patch: set
Needs documentation: set
Owner: changed from nobody to Roman
Status: newassigned

comment:24 Changed 8 months ago by Mariusz Felisiak

Needs documentation: unset
Triage Stage: AcceptedReady for checkin

comment:25 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

In d44951b3:

Refs #7497 -- Added assertion for the default order of models in AdminSite.app_index().

comment:26 Changed 8 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In 2bee0b4:

Fixed #7497 -- Allowed overriding the order of apps and models in admin.

Note: See TracTickets for help on using tickets.
Back to Top