Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@PythonicNinja
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PythonicNinja/8f4fbcdba9ec4cb8de7c to your computer and use it in GitHub Desktop.
Save PythonicNinja/8f4fbcdba9ec4cb8de7c to your computer and use it in GitHub Desktop.
import django models in django console all django versions
from django import VERSION
if VERSION[0]+VERSION[1]*0.1 >= 1.7:
import django
from django.apps import apps
django.setup()
models = apps.get_models()
else:
from django.db.models.loading import get_models
models = get_models()
for m in models:
exec "from %s import %s" % (m.__module__, m.__name__)
@PythonicNinja
Copy link
Author

Auto imports all models to use in django console

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment