Hi,
I just got an application installed several times in one project.
It was important for me, that each instance of the application
has it on tables.
Here is who I did it. Feedback welcome!
myapp: Exists one time, but never gets used in settings.INSTALLED_APPS
I created two new modules on the PYTHONPATH with symlinks myapp_inst1
myapp_inst2. Both
directories point to myapp.
in settings INSTALLED_APPS = [ .., 'myapp_inst1', 'myapp_inst2']
I changed all absolute imports in the application to relative imports:
old: from myapp.utils import abc
new: from .utils import abc
in myapp/__init__.py:
import os
application=os.path.basename(os.path.dirname(os.path.abspath(__file__)))
in myapp/models:py:
assert application.startswith('myapp_'), 'Wrong Import. application=%s
should be myapp_instN.' % (
application)
Now syncdb creates the tables like this: myapp_inst1_mymodel
# urls.py need to prefix the viewnames with application:
myapp/urls.py:
urlpatterns = patterns('',
(r'^$', '%s.views.index' % application),
...
One place left: Templatetag 'url' needs to use relative imports, too.
I modified django: if the view name starts with a dot, the view name gets
the application as prefix. The variable 'application' must be contained
in the context.
Index: django/template/defaulttags.py
===================================================================
--- django/template/defaulttags.py (Revision 7425)
+++ django/template/defaulttags.py (Arbeitskopie)
@@ -359,12 +365,16 @@
args = [arg.resolve(context) for arg in self.args]
kwargs = dict([(smart_str(k,'ascii'), v.resolve(context))
for k, v in self.kwargs.items()])
+ if self.view_name.startswith('.'):
+ view = '%s%s' % (context['application'], self.view_name)
+ else:
+ view = self.view_name
try:
- return reverse(self.view_name, args=args, kwargs=kwargs)
+ return reverse(view, args=args, kwargs=kwargs)
except NoReverseMatch:
try:
project_name = settings.SETTINGS_MODULE.split('.')[0]
- return reverse(project_name + '.' + self.view_name,
+ return reverse(project_name + '.' + view,
args=args, kwargs=kwargs)
except NoReverseMatch:
return ''
Any thoughts how to do this better?
Thomas
--
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---