Run shell_plus though PyCharm?

Is there a way to configure PyCharm to run shell_plus instead of the default shell?

I tried to put the text of the control command in the "Initial script", but then I got the following django_manage_shell.run ("/ Users / cmason / Counsyl / code / site / Counsyl / product") import OS import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")

    # The new Django 1.4 default manage.py wants "from django..." before
    # importing settings, but we usually tinker with sys.path in
    # settings_local.py, which is called from settings.py. Importing
    # settings.py works but does mean some double importing. Luckily that
    # module does very little work.
    import settings
    # appease pyflakes; don't ever do this in
    # non-super-meta-namespace-trickery code
    settings

    from django.core.management import execute_from_command_line

    execute_from_command_line("shellplus")

and he didn’t actually run shell_plus.

It appears that the "Run Script" is in addition, not the default.

Shell_plus automatically imports all classes of the Django model, by the way.

+8
source share
5 answers

, shell_plus. Preferences > Build, Execution, Deployment > Console > Django Console:

from django_extensions.management import shells
from django.core.management.color import color_style
imported_items = shells.import_objects({}, color_style())
for k, v in imported_items.items():
    globals()[k] = v

PyCharm 2018.3.3 Pro

, :

import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django): django.setup()
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)

from django_extensions.management import shells
from django.core.management.color import color_style
imported_items = shells.import_objects({}, color_style())
for k, v in imported_items.items():
    globals()[k] = v
+3

, script, , , . > > Django > script:

import sys
import logging
logging.basicConfig(format="%(levelname)-8s %(asctime)s %(name)s %(message)s", datefmt='%m/%d/%y %H:%M:%S', stream=sys.stdout )
log = logging.getLogger("root")

from django.db.models import get_models
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned

logging.config.dictConfig(settings.LOGGING)
log.debug("Logging has been initialized at DEBUG")
log.setLevel( logging.DEBUG)
log.disabled = False

for _class in get_models():
    if _class.__name__.startswith("Historical"): continue
    log.debug("Registering model {}".format(_class.__name__))
    globals()[_class.__name__] = _class

def debug_sql():
    from debug_toolbar.management.commands import debugsqlshell
    return

JetBrains.

+2

Django 1.7, script PyCharm 3.4:

→ → → Django manage.py

Starting script, :

import sys
import django
django.setup()

from django.db.models import get_models

for _class in get_models():
    globals()[_class.__name__] = _class
+1

django.db.models.get_models , , , .

import sys; print('Python %s on %s' % (sys.version, sys.platform))
import django; print('Django %s' % django.get_version())
import logging
logging.basicConfig(format="%(levelname)-8s %(asctime)s %(name)s %(message)s", datefmt='%m/%d/%y %H:%M:%S', stream=sys.stdout )
log = logging.getLogger("root")

from django.apps import apps
from django.conf import settings  
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned

logging.config.dictConfig(settings.LOGGING)
log.debug("Logging has been initialized at DEBUG")
log.setLevel( logging.DEBUG)
log.disabled = False

for _configs in apps.get_app_configs():
    for _class in _configs.get_models():
        if _class.__name__.startswith("Historical"): continue
        log.debug("Registering model {}".format(_class.__name__))
        globals()[_class.__name__] = apps.get_model(_configs.label, _class.__name__)

def debug_sql():
    from debug_toolbar.management.commands import debugsqlshell
    return
0

, , , . , . -. , :

Django Console PyCharm 2019.2.3:

import sys, django
print('Python %s on %s' % (sys.version, sys.platform))
print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
if 'setup' in dir(django):
    django.setup()
import django_manage_shell
django_manage_shell.run(PROJECT_ROOT)

, .

from IPython.core.getipython import get_ipython
ipython = get_ipython()
from django_extensions.management.notebook_extension import load_ipython_extension
load_ipython_extension(ipython)

, PyCharm (CTRL + S) Django " ", . Python.

0

All Articles