Skip to content

Instantly share code, notes, and snippets.

@imomaliev
Last active August 29, 2015 14:13
Show Gist options
  • Save imomaliev/3417451c9142889ff572 to your computer and use it in GitHub Desktop.
Save imomaliev/3417451c9142889ff572 to your computer and use it in GitHub Desktop.
Pycharm python console, for ipython with preloaded models
import os
import sys
import django
print('Django %s' % django.get_version())
sys.path.extend([WORKING_DIR_AND_PYTHON_PATHS])
sys.path.extend(['/Applications/PyCharm CE.app/Contents/helpers'])
sys.path.extend(['/Applications/PyCharm CE.app/Contents/helpers/pycharm'])
if 'setup' in dir(django): django.setup()
PROJECT_ROOT = WORKING_DIR_AND_PYTHON_PATHS
import django_manage_shell; django_manage_shell.run(PROJECT_ROOT)
def color_style():
from django.utils import termcolors
"""Returns a Style object with the Django color scheme."""
DJANGO_COLORS = os.environ.get('DJANGO_COLORS', '')
color_settings = termcolors.parse_color_setting(DJANGO_COLORS)
if color_settings:
class dummy: pass
style = dummy()
for role in termcolors.PALETTES[termcolors.NOCOLOR_PALETTE]:
format = color_settings.get(role,{})
setattr(style, role, termcolors.make_style(**format))
style.ERROR_OUTPUT = style.ERROR
else:
style = no_style()
return style
def run_ipython():
from django_extensions.management.shells import import_objects
from IPython import embed
imported_objects = import_objects({'dont_load': []}, color_style())
get_ipython().user_ns.update(imported_objects)
run_ipython()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment