1

Python version: 2.7 & Django version: 1.5.1

I'm currently working on developing a backend app for phpbb3. Our current implementation in PHP is eating up far too many resources.

I'm about 90% done, but I am hung up on a small snag when it comes to configuration.

We have multiple forums that the script needs to run on, and each one has its own database, such as site1, site2, and site3 database. Django has its own database as well.

What I need to do is specify settings for my script, based upon each site and the forums on the site. So I need to acquire the forums that exist on site1 and then in the admin panel they can select site 1 and choose a forum and pick their configuration from there. They could then pick site 2, and pick a forum from site 2 and then set their data their.

I do not want to create a django site for each site that we are running, and I would like to make it easy as possible to add a new site, but I am not opposed to making a new app for each site if that is what is needed?

What would be the best method for dynamically pulling the forums from another database and associating it with a site value, and providing configuration models for that forum. (I don't want them to be able to pick a forum that exists on another site)

lalit
  • 3,283
  • 2
  • 19
  • 26
iargue
  • 69
  • 2
  • 13
  • Can you provide some more details about your phpbb setup with django? – lalit May 01 '13 at 05:56
  • @lalit What more information would you like to know? There are multiple sites setup using PHPBB and they all have their own database name, so site1 has a database called site1, and inside there are all of the standard phpp forums with the standard phpbb_ prefix. The django site is setup under its own database. I need an admin page that lets me pick/create a site and then from that site, pull the proper database and provide the proper forum models and setup config for each forum that exists in phpbb's database. – iargue May 01 '13 at 15:36
  • Thanks @user1189764, So to be more specific on functionality, do you want to achieve following: different databases for different sites, way to access django and phpbb database together and an admin Interface to select a site and corresponding database. – lalit May 01 '13 at 16:22
  • @lalit Yes. With the ability to apply settings to just that site/database. – iargue May 01 '13 at 22:40

1 Answers1

1

Here are some of the pointers, using which you can achieve above functionality:

1. Different Database for different Django Sites.

You can find a related question here, Which explains how you can setup a custom router for Database.

2. Way to access django and phpbb database together.

There is one Github project available here, which might help you in this.

3. Admin Interface to select a site, corresponding database and apply settings.

The simplest option for this will be to dump your settings in Dictionary or File or combination of both and based on your site ID select settings present in that dictionary for that particular site.

To be really honest, I don't feel that you need a Admin Inteface here. But still, if there is any requirement that I am Not aware of, then you can write a simple view to handle above things and provide its access from admin panel.

Hopefully this solves your problem.

Community
  • 1
  • 1
lalit
  • 3,283
  • 2
  • 19
  • 26
  • I can't even test or work on the last part, because the first part (number 1) is completely wrong. I get errors left and right trying to use their method. For instance, based on their setup, it wouldn't work, and so I moved it to its own file and referenced it inside of the django settings and the router would register, but would fail. Then I added from django.conf import settings, but adding from django.contrib.sites.models import Site so it could load the site name failed saying ImproperlyConfigured: Error importing database router CustomDatabaseRouter: "cannot import name connection" – iargue May 02 '13 at 19:06
  • Okay. I got the first section working (Supposedly) but I am still running into issues amongst the other things. I am trying to setup the admin page, but I am really confused on how to set this up. I don't think/know if the internal site framework will work, because I'm not running the django project on more then 1 site. The django project only has a single domain, and only gets accessed from that domain, so I'm not sure how to associate the site variable without accessing it from a different domain. Nor am I sure how to associate the modules with the different sites – iargue May 02 '13 at 19:23
  • Hi, I think I am a little unclear about your requirements. Do you want to use different forum and database under same django project and site, based on selection in admin panel? – lalit May 03 '13 at 06:31
  • Yes, that is what I am hoping to accomplish. – iargue May 03 '13 at 13:51
  • In that case storing the data into a dictionary or file might Not make sense as only one forum and database will be used at a time. Rather, maintain these things in database table where each record will tell you configurations/settings (forums, database or scripts) required for a particular forum. Proabably you might also need a flag kind of field (column) 'is_active' to define, if forum is currently activate. – lalit May 03 '13 at 15:05
  • Also please check this: http://stackoverflow.com/questions/10053981/how-can-i-create-custom-page-for-django-admin – lalit May 03 '13 at 15:06