Multiple instance of the same app

139 views
Skip to first unread message

Kepioo

unread,
Apr 18, 2010, 2:58:28 PM4/18/10
to Django users
Hi All,

I am trying to come up with a climbing guide website. My original
design was to have :
a guide app that defines the abstract models, the views and urls
n climbing sites that extend the climbing app


mysite/
guide
climbingsite1
climbingsite2
climbingsite3
...


The main motivation behind this was to have dedicated tables for each
climbingsites ( so that I can drop them if I need) and to be able to
control the admin priviledges at the climbing site level.

I got the site somewhat setup ( with the latest trunk), but I am
having a really hard time getting the url template tag working.

the main url.py looks like this :

urlpatterns = patterns('',
(r'^erock/',include('climbguide.guide.urls'),
{'current_app':'erock'}),
(r'^backyard/',include('climbguide.guide.urls'),
{'current_app':'backyard'}),
)

guide.urls :
urlpatterns = patterns('climbguide.guide.views',
url(r'^area/(?P<area_id>[^/]+)/$', 'view_area',name='view_area'),
)
~


within climbguide.guide.views I have views that look like :
def get_model(app,model):
mod = __import__('climbguide.%s.models'%app, globals(), locals(),
model)
return getattr(mod, model,None)

def view_area(request,area_id,current_app'):
area = get_object_or_404(get_model(current_app,'Area'),
pk=area_id)
context_instance = RequestContext(request,
current_app=current_app,)
return render_to_response('guide/view_area.html',
{'area':area},context_instance=context_instance,)


The problem I am experiencing is in my template, if I do a
{% url view_area 3 %}, it returns the url for /erock/area/3, even when
the current_app is set to backyard (which is expected, as details in
the namespace doc : it returns the first app with the pattern).


I have the feeling I am missing something - the whole new addition of
the namespace is suppose to help deploy multiple instance of the same
app, but somehow, I am not using it properly, or even getting it !

I am seeking your help to guide me in the right direction.

Thank you.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Benjamin Reitzammer

unread,
Apr 19, 2010, 3:39:55 AM4/19/10
to django...@googlegroups.com
Hi,
maybe I missed something in you explanation, but if you want the same
code powering multiple sites and each of the sites' data reside in
their own database, while all sites still have the same model (this is
were I'm unsure if I understood you correctly), why don't you simply
use multiple settings.py files?

Cheers, Benjamin

Kepioo

unread,
Apr 19, 2010, 1:49:52 PM4/19/10
to Django users
Hi Ben- i actually want all the climbing sites in the same db, same
server - that's why i didnt go for the sites framework.

On Apr 19, 2:39 am, Benjamin Reitzammer <benja...@squeakyvessel.com>
wrote:
> > For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Django users" group.
> To post to this group, send email to django...@googlegroups.com.
> To unsubscribe from this group, send email to django-users...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Bill Freeman

unread,
Apr 20, 2010, 10:23:20 AM4/20/10
to django...@googlegroups.com
Why not add a "site" field to the model(s)? You can filter for the current
site by hand, or have individual model managers for the various sites
that you select at the top of the view (maybe in a decorator?).
Reply all
Reply to author
Forward
0 new messages