An extended Django shell
Project description
django-shell-extended
Provides a sh management-command that can be customized via django settings.
Quick start
- Install with
pip install django-shell-extended - Add
"django_shell_extended"to yourINSTALLED_APPSsetting like this:INSTALLED_APPS = [ # ... "django_shell_extended", ]
- (Optional) Change the settings described in the next section in your
settings.py - Start the shell via
python manage.py sh
Available settings
# The Path to a custom ipython directory.
# default: None
DJANGO_SH_IPYTHON_DIR = "/some/path/.ipython/"
# Tries to autodetect django apps with models and imports them as `from my_app.models import *`
# default: True
DJANGO_SH_AUTO_IMPORT_MODELS = True
# Defines additional modules that should be imported.
# Should be a tuple or list containing entries like `(module, imports)`.
# default: ()
DJANGO_SH_IMPORT_MODULES = (
('datetime', ('datetime', 'timedelta')), # -> from datetime import datetime, timedelta
('re', None), # -> import re
('decimal', 'Decimal'), # -> from decimal import Decimal
('foo.bar', '*') # -> from foo.bar import *
)
# A function that adds command line arguments to the `sh` command.
# default: None
def DJANGO_SH_HOOK_ADD_ARGUMENTS(parser: CommandParser) -> None:
parser.add_argument(...)
# A function that is called after importing models and modules.
# Can be used to further extend the `imported_objects` name space or to check command arguments. Example::
# default: None
def DJANGO_SH_HOOK_GET_IMPORTED_OBJECTS(imported_objects: dict, options: dict) -> None:
multiplier = int(options.get('multiplier', 0))
imported_objects['multiply'] = lambda x: x * multiplier
# Can be used to alter the command provided to `python manage.py sh -c '<command>'`
# default: None
def DJANGO_SH_HOOK_MODIFY_COMMAND(command: str) -> str:
return f'start=time.time()\\n{command}\\nprint("Command took", time.time() - start, "seconds")'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_shell_extended-1.0.0.tar.gz.
File metadata
- Download URL: django_shell_extended-1.0.0.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
733f0936f6f332c32f3d7f48523e7210dcf4c3967fe0350628899077131bd619
|
|
| MD5 |
55b5d3b68b3282520257cad84b95e7af
|
|
| BLAKE2b-256 |
a527f1e5833dab288c7088b10b87de4910ce8a462703caa25d1d4b6ee0535452
|
File details
Details for the file django_shell_extended-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_shell_extended-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b3fa6f1231badcbd9581c9089e0c77d64e24a8db8e17142e5f3a356fc28d3eb1
|
|
| MD5 |
6780ea45c6da1cf2dac1c540260c1504
|
|
| BLAKE2b-256 |
eac6d2c42427461a5c6a7f522ed13b8e93f2e5ca37a33711d397f6ee2667459e
|