Skip to content

Instantly share code, notes, and snippets.

@erickgnavar
Forked from chris-ramon/django_shell.py
Created September 12, 2013 21:49
Show Gist options
  • Save erickgnavar/6544351 to your computer and use it in GitHub Desktop.
Save erickgnavar/6544351 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
#coding:utf-8
import sys
import os
from random import randint, random
sys.path.insert(0, os.path.expanduser('PATH_OF_YOUR_DJANGO_PROJECT'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings.py'
from django.contrib.contenttypes.models import ContentType
from django.contrib.auth.models import User
from django.db.models.loading import get_models
for m in get_models():
exec "from %s import %s" % (m.__module__, m.__name__)
# custom models
from apps.rp.models.User import CustomUser
# printing the queries
import logging
l = logging.getLogger('django.db.backends')
l.setLevel(logging.DEBUG)
l.addHandler(logging.StreamHandler())
# sublime virtual env config
{
"cmd": ["python", "-u", "$file"],
"env": {"PYTHONPATH": "/home/chris/venvs/venv-rp/lib/python2.7/site-packages"},
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.python"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment