From a5cd84ad2002f9a43363ab9fd9d9f6e9dfa48c60 Mon Sep 17 00:00:00 2001 From: Salvo Polizzi Date: Fri, 14 Feb 2025 08:17:25 +0100 Subject: Fixed #35680 -- Added automatic imports of common utilies to shell management command. --- docs/howto/custom-shell.txt | 17 +++++++++++++---- docs/ref/django-admin.txt | 17 ++++++++++++++--- docs/releases/6.0.txt | 3 +++ 3 files changed, 30 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/howto/custom-shell.txt b/docs/howto/custom-shell.txt index c1632849b5..cf55a02400 100644 --- a/docs/howto/custom-shell.txt +++ b/docs/howto/custom-shell.txt @@ -39,20 +39,29 @@ For example: The customization above adds :func:`~django.urls.resolve` and :func:`~django.urls.reverse` to the default namespace, which already includes -all models from the apps listed in :setting:`INSTALLED_APPS`. These objects -will be available in the ``shell`` without requiring a manual import. +all models from the apps listed in :setting:`INSTALLED_APPS` plus what is +imported by default. These objects will be available in the ``shell`` without +requiring a manual import. Running this customized ``shell`` command with ``verbosity=2`` would show: .. console:: - 8 objects imported automatically: - + 13 objects imported automatically: + + from django.db import connection, reset_queries, models + from django.conf import settings from django.contrib.admin.models import LogEntry from django.contrib.auth.models import Group, Permission, User from django.contrib.contenttypes.models import ContentType from django.contrib.sessions.models import Session from django.urls import resolve, reverse + from django.utils import timezone + +.. versionchanged:: 6.0 + + Automatic imports of common utilities, such as ``django.conf.settings``, + were added. If an overridden ``shell`` command includes paths that cannot be imported, these errors are shown when ``verbosity`` is set to ``1`` or higher. Duplicate diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt index a1603c9e84..22a7c0a10c 100644 --- a/docs/ref/django-admin.txt +++ b/docs/ref/django-admin.txt @@ -1067,9 +1067,15 @@ Starts the Python interactive interpreter. All models from installed apps are automatically imported into the shell environment. Models from apps listed earlier in :setting:`INSTALLED_APPS` take -precedence. For a ``--verbosity`` of 2 or higher, the automatically imported -objects will be listed. To disable automatic importing entirely, use the -``--no-imports`` flag. +precedence. The following common utilities are also imported:: + + from django.db import connection, reset_queries, models + from django.conf import settings + from django.utils import timezone + +For a ``--verbosity`` of 2 or higher, the automatically imported objects will +be listed. To disable automatic importing entirely, use the ``--no-imports`` +flag. See the guide on :ref:`customizing this behavior ` to add or remove automatic imports. @@ -1078,6 +1084,11 @@ See the guide on :ref:`customizing this behavior Automatic models import was added. +.. versionchanged:: 6.0 + + Automatic imports of common utilities, such as ``django.conf.settings``, + were added. + .. django-admin-option:: --interface {ipython,bpython,python}, -i {ipython,bpython,python} Specifies the shell to use. By default, Django will use IPython_ or bpython_ if diff --git a/docs/releases/6.0.txt b/docs/releases/6.0.txt index 6a819ecc3f..a7306ba755 100644 --- a/docs/releases/6.0.txt +++ b/docs/releases/6.0.txt @@ -224,6 +224,9 @@ Management Commands * The :djadmin:`startproject` and :djadmin:`startapp` commands now create the custom target directory if it doesn't exist. +* Common utilities, such as ``django.conf.settings``, are now automatically + imported to the :djadmin:`shell` by default. + Migrations ~~~~~~~~~~ -- cgit v1.3