0

I wrote a django project that is some kind of a CMS. Now, I want to be able to create several accounts that use that CMS, Each with a different database. For example, user can create himself an account in my service - and he will get a site based of that CMS. How can I get started doing this?

user2216190
  • 784
  • 5
  • 10
  • 25

2 Answers2

0

Look at the django docs https://docs.djangoproject.com/en/dev/topics/db/multi-db/ There are is useful example. Another good article https://thenewcircle.com/s/post/1242/django_multiple_database_support

minskster
  • 512
  • 3
  • 6
0

Unfortunately Django is not suited to dynamically switch databases at runtime. You either have to implement really hackish solutions (like mentioned in this question Django multiple and dynamic databases ) or to go with several independent Django instances which you will have to start up on your server dynamically.

A much simpler solution would be to stick to one database and distinguish different users' content by some other means, like Django Sites framework. The only problem with this approach in my opinion is that you will have to carefully set up your admin site configuration, so that users don't see each other's objects (in case you planned to use built-in Django admin).

Community
  • 1
  • 1
Spc_555
  • 4,081
  • 2
  • 27
  • 34
  • Lets go with the second solution - So for example if we have a table that contains blog posts, each post will have a row describing to which account it is related? isn't it super security leak? and lets say we have 100k blog post, running over the database each time will be very slow, isn't it? – user2216190 Sep 08 '14 at 18:30
  • Where do you see a security leak? Almost every site distinguishes different users' content this way. You don't expect Stack Overflow to have a separate DB for you to store your questions, do you? As for performance issues, it sure will be somewhat slower, but in fact search on an indexed integer field is pretty fast (and foreign keys are always indexed), so I don't really think this should be a concern. – Spc_555 Sep 08 '14 at 18:55