67👍
✅
install django-extensions, one of the commands it features (shell_plus) is providing the context for your models.
https://github.com/django-extensions/django-extensions
So, instead of ./manage.py shell
you can use ./manage.py shell_plus
so that everything is imported.
8👍
http://docs.python.org/using/cmdline.html#envvar-PYTHONSTARTUP
If you set the environment variable PYTHONSTARTUP
to a file, this will be run first whenever you start a python shell.
- [Django]-Django: how do you serve media / stylesheets and link to them within templates
- [Django]-Django-rest-framework 3.0 create or update in nested serializer
- [Django]-How to set up a Django project in PyCharm
0👍
Create a file.py
file in the same directory as manage.py
file with all imports that you need.
For example:
from django.core.cache import cache; from django.db.models import Prefetch, Count, Q; from django.db import connection, reset_queries; from datetime import timedelta; from django.utils import timezone;
Then, every time after you launch the shell, simply import that file: from file import *
- [Django]-Sending post data from angularjs to django as JSON and not as raw content
- [Django]-Unsupported operand type(s) for *: 'float' and 'Decimal'
- [Django]-How do I get the values of all selected checkboxes in a Django request.POST?
Source:stackexchange.com