Skip to content

Instantly share code, notes, and snippets.

@PythonicNinja PythonicNinja/import.py
Last active Aug 29, 2015

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

commented Sep 29, 2014

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
You can’t perform that action at this time.