Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It looks like you want to replicate features of other popular languages and frameworks in Django. Reading your post OSGi springs to mind.</p> <p>The problem is that 99,9% of all Django applications are not "dynamic" in the sense that apps can be installed, loaded, unloaded and uninstalled at runtime. That's not how Django applications work. You install an app before the application is started. To uninstall an app you shutdown your application and remove it from the <code>INSTALLED_APPS</code> (settings.py) list. Since this does not happen at runtime there won't be any signals, callbacks or other things to the Django application. </p> <p>But there are certain things you can do to at least meet some of your needs. From the top of my head I think you could do something like a <code>before_install</code> and <code>after_install</code> "signal" (not in the Django signal sense).</p> <p>To do so you could write some sort of "controller" or "registry" app. One for the <code>before_install</code> and one for <code>after_install</code> code. Those apps would sit before and after the rest of your apps in <code>INSTALLED_APPS</code>.</p> <p>e.g.</p> <pre><code>INSTALLED_APPS = ( # all the Django apps and other third party apps 'before_install_controller_app', # all your in-house apps 'after_install_controller_app', ) </code></pre> <p>These two apps iterate all the apps listed under <code>INSTALLED_APPS</code>. They try to import a specific python file from each of the apps. If the file is not in the app (because it's a Django or third-party app) nothing happens. But if there is a file, let's call it <code>before_install.py</code> and <code>after_install.py</code> it is loaded and the code inside is run.</p> <p>The same would apply for the <code>after_install_controller_app</code> app, but it would look for <code>after_install.py</code>.</p> <p>It's basically the same mechanism Django uses for it's admin. The admin app iterates all the apps and tries to import <code>admin.py</code>. That's why you should at first have a look at the corresponding <a href="http://code.djangoproject.com/svn/django/trunk/django/contrib/admin/__init__.py" rel="nofollow">Django source</a>. It's pretty straight forward and easy to understand. I did something similar and it worked like a charm.</p> <p>There are of course some limitations. For instance:</p> <ul> <li>The before_install.py code would not have access to database models of the underlying app because they may be a) not have been created yet (see order of the apps) or b) out of date.</li> <li>I am sure there are many more, but at the moment I don't find any more.</li> </ul> <p>On last thing:</p> <p>Don't try to hard to map/port features/paradigms of one programming language/frameworks to another. There might be fundamental differences that render good approaches in one language/framework useless in another. That certainly seems the case here.</p> <p>If you have further questions I'd be glad to help if I can.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload