Opened 10 years ago

Closed 10 years ago

#21712 closed Cleanup/optimization (fixed)

Move admin.autodiscover() to AppConfig.setup()

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: contrib.admin Version: dev
Severity: Normal Keywords: app-loading
Cc: Triage Stage: Ready for checkin
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Aymeric Augustin)

It doesn't belong to urls.py!

This probably requires shipping an apps.py with an AppConfig in the default project template and adding lots of documentation, including in the tutorial.

Change History (13)

comment:1 by Aymeric Augustin, 10 years ago

Description: modified (diff)

In fact, we don't have a good API for project-level startup code. Many projects have a "project app" for projectwide templates, staticfiles, etc. but the tutorial doesn't. This requires a bit more thought.

comment:2 by Aymeric Augustin, 10 years ago

It may be more appropriate to put it in the admin AppConfig (once there's one, #21675) and to document how do disable it (via subclassing).

comment:3 by Aymeric Augustin, 10 years ago

Summarizing a discussion with Marc on IRC:

  • https://gist.github.com/mjtamlyn/8209667
  • explain in the release notes to use 'django.contrib.admin.app.AdminConfig' instead of 'django.contrib.admin' in INSTALLED_APPS and remove admin.autodiscover() from urls.py.

comment:4 by Marc Tamlyn, 10 years ago

PR submitted. There are at least three things to consider which are in the PR - including naming of the file, default project and testing.

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

comment:5 by Bas Peschier, 10 years ago

I would change the default project to use the AdminConfig. My guess is most people use the autodiscover method. People implementing their own AdminSite can read the documentation about it.

comment:6 by Claude Paroz, 10 years ago

+1 to change the default project.
I'd keep the app.py name. apps.py would suggest several applications.
I'd also add verbose_name = _("Django administration").

comment:7 by Marc Tamlyn, 10 years ago

The last point about the verbose_name is tracked in #21675 as it covers all contrib apps.

comment:8 by Aymeric Augustin, 10 years ago

Yes, we must change the default project template. We should also copy-paste the usual warnings in the tutorial for people who don't check properly what version they're using.

We've decided to always use apps.py. Let's stick with that.

comment:9 by Aymeric Augustin, 10 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned

comment:10 by Aymeric Augustin, 10 years ago

It's impossible to make this change in the test suite because it relies on the admin autodiscovery not being run.

The bug8245 test app contains an invalid admin module that breaks autodiscovery.

comment:11 by Aymeric Augustin, 10 years ago

Triage Stage: AcceptedReady for checkin

New PR: https://github.com/django/django/pull/2182

I think it's good to go but I would appreciate a proof-read. It's mostly a documentation patch.

comment:12 by Claude Paroz, 10 years ago

I've only read the patch, but it looks good to me (except reported typos).

comment:13 by Aymeric Augustin <aymeric.augustin@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In 10e0cfc0e4e77b85e8261c908baf1c4814ded3f8:

Fixed #21712 -- Moved autodiscover() to AdminConfig.ready().

Thanks Marc Tamlyn for the initial version of the patch.

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