Opened 3 years ago

Closed 3 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: master
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 Changed 3 years ago by Aymeric Augustin

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 Changed 3 years ago by Aymeric Augustin

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 Changed 3 years ago by Aymeric Augustin

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 Changed 3 years ago by Marc Tamlyn

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 Changed 3 years ago by Bas Peschier

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 Changed 3 years ago by Claude Paroz

+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 Changed 3 years ago by Marc Tamlyn

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

comment:8 Changed 3 years ago by Aymeric Augustin

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 Changed 3 years ago by Aymeric Augustin

Owner: changed from nobody to Aymeric Augustin
Status: newassigned

comment:10 Changed 3 years ago by Aymeric Augustin

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 Changed 3 years ago by Aymeric Augustin

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 Changed 3 years ago by Claude Paroz

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

comment:13 Changed 3 years ago by Aymeric Augustin <aymeric.augustin@…>

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