You have a bunch of possibilities to solche your problems - sharing code/the models isn't the biggest problem as, if you package them in some re-usable apps you should be able to use them in different projects.
Use Django's Sites framework: So both sites will basically run with the same code, use the same database. Content objects will have a
ForeignKey
pointing to aSite
. This works well if your sites have exactly the same functionality, maybe only different design. If the you would have to have to dig deeper in Python code to customize one site this is probably not the best alternative.You could find a solution with a database for the users and one for each site and share the users using DB routers. The main disadvantage of this is that user data and other data lives in seperate databases, meaning you can't perform JOINs or something like that on them. (This would seperate your data very cleanly, no need to filter if some content belongs to a site or not)
Write you own authentication backend so that each project doesn't authenticate the user against its own database, but against some external service.
I think easiest is going with the sites framework, though if one site needs deeper customizations that may affect the other site (such as other db schema per instance) this might get tricky and you should keep in mind that every change might also affect the other site.
To configure this solution you need to have a seperate settings file for each site (you need to at least set SITE_ID
per site). Additionally you could specifiy additional settings like different template folders etc individually for each site.
settings
__init__.py
base.py
site_a.py
# site_a.py
from base import *
SITE_ID = 1
# eg different templates for this site
TEMPLATE_DIRS = (('site_a/templates/'),)
The development server you can run then with manage.py --settings settings.site_a
.
You could eg. also use a different urls.py
per site if you specify it in the settings.
In production you need to have two instances running, one with the settings for each site and eg. have a reverse proxy sending the requests to the right instance.