Django Multi-site with shared database
<p>I am about to develop multiple sites for different real estate companies. All share the same html, sections, etc. The difference is in the content, specially the properties... But some of those properties can be shared among the rest of the companies.</p>

<p>I am thinking in sharing the same database and differentiate content using the url. In this way I can use only one project instead of one for each company.</p>

<p>Does anyone have recommendations for this kind of projects?</p>

<p>Thanks,</p>

<p>I have done that.<br>
Was it a good idea? Yes, in my case it was. I had to reuse the same content and when we changed the content, it had to be changed on all pages. On a simple site, a triple deploy and changing the content in three different projects is kind of overkill. But whereas it works fine in a simple front-end page (that hardly even requires Django), I do not recommend it for "real" web apps.  </p>

<p>What will break? Think about the things that your pages will share and see if it's a problem.  </p>

<p>1) I'm guessing that if you'll want to have user login capability on the page (besides the admin login), then that's a problem, if I can use the same user for different companies that have no apparent connection whatsoever. You could be in for a lot of trouble if the companies find out that user private details aren't as private as they thought. And the same goes for the users who really don't have a clue how they ended up with a user account on a page they've never visited.   </p>

<p>2) URLs. You can't have different ones for each company without some extra hacking. If one of the companies wants to have <code>/about/</code> and the other one <code>/company/</code> page, you're gonna start hacking a bad solution that will blow up in your face when the companies ask for the next page.</p>

<p>3) Anything else you might want to have on your page that is connected to hardcoded data or database values. I.e. social authentication etc.</p>

<p>What can you do about it?  </p>

<p>If I was hellbound on solving the first one, here's what I would do:<br>
- Override the user model and add info about the registering page<br>
- Create custom managers for user model for each page<br>
- Write a middleware that only lets you use the page-specific manager for the current request<br>
All in all, I wouldn't do it in a million years. Way too hacky, way too vulnerable. Just create separate databases.  </p>

<p>For solving the second one, you can create a multi-host middleware that checks from which domain the request comes from and returns the correct URL config. Sth similar to <a href="https://djangosnippets.org/snippets/1509/" rel="nofollow">this</a> . It's not really hard to rewrite and modify to your needs.</p>

<p>It's impossible to decide for you, but I've given you something to think about before going one way or the other. Good luck!</p>

python django