diff options
| author | Salvo Polizzi <salvopolizzi03@gmail.com> | 2025-02-14 08:17:25 +0100 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2025-07-17 12:51:43 +0200 |
| commit | a5cd84ad2002f9a43363ab9fd9d9f6e9dfa48c60 (patch) | |
| tree | e2307cc155727fe1ecd7042a215689ef1df507b5 /django | |
| parent | 8499fba0e18826a77fe32cbc13a3d951d9ca8924 (diff) | |
Fixed #35680 -- Added automatic imports of common utilies to shell management command.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/commands/shell.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py index 132e7f89d2..25edc80f7c 100644 --- a/django/core/management/commands/shell.py +++ b/django/core/management/commands/shell.py @@ -124,13 +124,19 @@ class Command(BaseCommand): def get_auto_imports(self): """Return a sequence of import paths for objects to be auto-imported. - By default, import paths for models in INSTALLED_APPS are included, - with models from earlier apps taking precedence in case of a name - collision. + By default, import paths for models in INSTALLED_APPS and some common + utilities are included, with models from earlier apps taking precedence + in case of a name collision. For example, for an unchanged INSTALLED_APPS, this method returns: [ + "django.conf.settings", + "django.db.connection", + "django.db.reset_queries", + "django.db.models", + "django.db.models.functions", + "django.utils.timezone", "django.contrib.sessions.models.Session", "django.contrib.contenttypes.models.ContentType", "django.contrib.auth.models.User", @@ -140,7 +146,15 @@ class Command(BaseCommand): ] """ - app_models_imports = [ + default_imports = [ + "django.conf.settings", + "django.db.connection", + "django.db.reset_queries", + "django.db.models", + "django.db.models.functions", + "django.utils.timezone", + ] + app_models_imports = default_imports + [ f"{model.__module__}.{model.__name__}" for model in reversed(apps.get_models()) if model.__module__ |
