You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Have an easy way to start a shell with all the relevant models (and maybe other helpers) autoloaded.
馃摃Context
The django-extensions project provides a nice autoloading of models etc when using the shell_plus command. However, django-extensions also includes a whole grab-bag of other stuff we don't necessarily want to include.
There are potentially a couple of ways to do this.
One we have used previously is to include an ipython_config.py in the root of the project so a shell started there will autoload the models. The code (thanks @a-musing-moose ) is:
"""An IPython config script to import settings and modelsWhen IPython is installed Django will automatically use it when you ask for a `shell`. This littleipython config script is loaded by IPython on startup and will import the Django settings and allthe registered models.Warning: You will get errors if you try to run IPython directly as the Django framework will nothave been properly bootstrapped."""c=get_config() # noqac.InteractiveShellApp.exec_lines= [
"from django.conf import settings",
"print('\\nImported \u001b[32;1msettings\u001b[0m from \u001b[37;1mdjango.conf\u001b[0m')",
"from django.apps import apps",
"import itertools",
"globals().update({m.__name__: m for m in apps.get_models()})",
"print(\"\\n\".join(['Imported \u001b[32;1m' + ', '.join([m.__name__ for m in g]) + f'\u001b[0m from \u001b[37;1m{k}\u001b[0m' for k, g in itertools.groupby(sorted(apps.get_models(), key=lambda m: m._meta.app_label), key=lambda m: m._meta.app_label)]))",
]
We could potentially approximately duplicate the functionality of the shell_plus part of django-extensions (but rewritten in such a way as to ensure no licensing problems).
Or we could just include django-extensions as a dev-only requirement (but we'd want to make sure we test without it!)
My main question is whether there are downsides or footguns to django-extensions that would make it problematic to use in dev but not install in prod. (Or maybe whether we would install it in prod too)
If not installing in prod, it would be important to ensure that when tests run in CI, they run in the absence of django-extensions which probably means making sure our requirements files break out dev, prod and test groups. (Side argument: if you have test tooling installed when running tests, how can you be sure prod will not fail in the absence of the test tooling!)
馃幆Aim
Have an easy way to start a shell with all the relevant models (and maybe other helpers) autoloaded.
馃摃Context
The django-extensions project provides a nice autoloading of models etc when using the
shell_plus
command. However,django-extensions
also includes a whole grab-bag of other stuff we don't necessarily want to include.There are potentially a couple of ways to do this.
One we have used previously is to include an
ipython_config.py
in the root of the project so a shell started there will autoload the models. The code (thanks @a-musing-moose ) is:We could potentially approximately duplicate the functionality of the
shell_plus
part ofdjango-extensions
(but rewritten in such a way as to ensure no licensing problems).Or we could just include
django-extensions
as a dev-only requirement (but we'd want to make sure we test without it!)馃摑Relevant resources/doc's/people
Slack thread where
django-extensions
came up (although it was talking more about generating a graph of the model relationships): https://ackama.slack.com/archives/CV0H0QML7/p1709941586747639Django extensions itself: https://django-extensions.readthedocs.io/en/latest/
鉁匒cceptance Criteria
The text was updated successfully, but these errors were encountered: