Reputation: 16721
Let's say we have a model called Event
with a slug name
. I'm looking to configure my Django app to basically isolate all my other models into separate apps depending on the event. For example:
"http://annualmeetup.domain.com" # in the form of "http://{}.domain.com".format(e.name)
How would I create completed isolated apps such that my models for users, meetings, and others only work in the context of the given subdomain? I was thinking about writing multiple apps for each event and copying the same models via a command script, but I still don't know how to point an app to a subdomain.
Upvotes: 2
Views: 699
Reputation: 31514
One option is to use django-tenant-schemas which is designed for this purpose:
Django provides currently no simple way to support multiple tenants using the same project instance, even when only the data is different. Because we don't want you running many copies of your project, you'll be able to have:
- Multiple customers running on the same instance
- Shared and Tenant-Specific data
- Tenant View-Routing (i.e., subdomain mapping)
This will result in you having separate database schema for each tenant (event, in your case), each with its own isolated models. Without too much effort you can create tenants (events) on the fly - it sounds like your use case would require that.
Note: tenant-schemas
only work with Postgres.
Upvotes: 5
Reputation: 753
You don't have to write separate apps for each event. If each event shares the same schema, you could just make your architecture Multitenant
Here are all the packages available for this. Link here
I personally recommend django-hosts
But it doesn't offer good data-isolation features. This is good if you already have an existing project and just want to introduce multitenancy. However, if you are just starting the project, django-tenancy
is a great option.
Upvotes: 0