Note that there are some explanatory texts on larger screens.

plurals
  1. PODjango application override & import path?
    primarykey
    data
    text
    <p>Let's have a django project using a 3rd party application. I'd like to override some of its modules without touching original files. Simple subclassing is not possible here, need to override code transparently as many other apps rely on original class names and functions.</p> <p>Project's structure looks like:</p> <pre><code>django_project/ __init__.py settings.py overrides/ &lt;-- here is a subdir with apps overrides __init__.py payment/ &lt;-- here is an example of app to override __init__.py admin.py forms.py &lt;-- this file is ignored, original is imported models.py tests.py views.py </code></pre> <p><code>settings.py</code> was modified with</p> <pre><code>INSTALLED_APPS=( 'satchmo_store.shop' #'payment' # original values 'overrides.payment' # modified app ... ) </code></pre> <p>The above solution however does not work, because Django does not insert path of added app into modules search path (<code>sys.path</code>). Django just loads <code>admin.py</code>, <code>models.py</code>, <code>tests.py</code> and <code>views.py</code>, other files like <code>forms.py</code> are ignored.</p> <p><strong>Is this behaviour documented somewhere ? What exactly placing a module name in INSTALLED_APPS does behind scenes ?</strong></p> <p>I hacked the situation with hardcoding new modules search path in <code>manage.py</code> and Apache's setting of WSGIPythonPath.</p> <pre><code>import os.path import sys DIRNAME = os.path.dirname(__file__) APPS_OVERRIDE = os.path.join(DIRNAME, 'overrides') if not APPS_OVERRIDE in sys.path: sys.path.insert(1, APPS_OVERRIDE) </code></pre> <p>I doubt this is the right way. Cann't find a guide describing apps overriding.</p> <p><strong>So, how can I properly override external Django application in my project ?</strong></p> <p>The bonus question: <strong>Do I need to copy whole application directory tree, not just particular files which are really modified ?</strong> As far as I know, Python stops at first matching module path, so it won't import other modules available in following parts of the search path.</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.
 

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