Django

Code

Ticket #10703 (closed: wontfix)

Opened 1 year ago

Last modified 1 year ago

Helper for importing modules from installed apps

Reported by: Archatas Assigned to: nobody
Milestone: 1.1 Component: Core framework
Version: 1.1-beta-1 Keywords: reusable utility extensible import dynamic
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

It would be really convenient to create extensible and reusable apps, if there was a simple way to import dynamically from an installed app (without defining the full path).

For example, there could be the following function defined somewhere in django.utils or django.db.models:

from django.db import models
from django.utils import importlib

def import_installed(path):
    """
    Imports a module from an installed app

    >>> import_installed("myapp.forms")
    <module 'myproject.apps.myapp.forms'>
    """
    app_name, module = path.split(".", 1)
    app = models.get_app(app_name)
    return importlib.import_module(app.__name__[:-6] + module)

Attachments

Change History

04/02/09 19:51:56 changed by ubernostrum

  • status changed from new to closed.
  • needs_better_patch changed.
  • resolution set to wontfix.
  • needs_tests changed.
  • needs_docs changed.

I don't really see the utility of this -- a properly-written Django application is just a Python module, and is importable the same as any other Python module. It's not like that module is suddenly going to have a different path (and if it does, you're doing something wrong).


Add/Change #10703 (Helper for importing modules from installed apps)




Change Properties
Action