Closed marimuthuinchennai closed 6 years ago
@marimuthuinchennai can you be more specific? What are you trying to do? Any code samples?
@marimuthuinchennai can you be more specific? What are you trying to do? Any code samples?
Ya Sure,
After creating tenant i need to redirect into particular tenant directly and i need to populate my tenant tables based on user login
@marimuthuinchennai can you be more specific? What are you trying to do? Any code samples?
from django.db import connection schema_name = connection.schema_name
from this i can able to populate public schema and similarly how to populate other schemas
Have you read the docs for this project? (docs)
To programmatically create a new tenant you would do the following:
from customers.models import Client, Domain
# create your first real tenant
tenant = Client(schema_name='tenant1',
name='Fonzy Tenant',
paid_until='2014-12-05',
on_trial=True)
tenant.save() # migrate_schemas automatically called, your tenant is ready to be used!
# Add one or more domains for the tenant
domain = Domain()
domain.domain = 'tenant.my-domain.com' # don't add your port or www here!
domain.tenant = tenant
domain.is_primary = True
domain.save()
Once that tenant is created you could redirect to a URL / subdomain for the newly created tenant/schema.
You can also act directly on a tenant schema with the following util:
from django_tenants.utils import tenant_context
with tenant_context(tenant):
# All commands here are ran under the schema from the `tenant` object
# Restores the `SEARCH_PATH` to its original value
I populate my database using celery with a couple of signals. The signal are called 'post_schema_sync' and 'post_schema_sync'
Have you read the docs for this project? (docs)
To programmatically create a new tenant you would do the following:
from customers.models import Client, Domain # create your first real tenant tenant = Client(schema_name='tenant1', name='Fonzy Tenant', paid_until='2014-12-05', on_trial=True) tenant.save() # migrate_schemas automatically called, your tenant is ready to be used! # Add one or more domains for the tenant domain = Domain() domain.domain = 'tenant.my-domain.com' # don't add your port or www here! domain.tenant = tenant domain.is_primary = True domain.save()
Once that tenant is created you could redirect to a URL / subdomain for the newly created tenant/schema.
You can also act directly on a tenant schema with the following util:
from django_tenants.utils import tenant_context with tenant_context(tenant): # All commands here are ran under the schema from the `tenant` object # Restores the `SEARCH_PATH` to its original value
Thank you for your Repsonse
I populate my database using celery with a couple of signals. The signal are called 'post_schema_sync' and 'post_schema_sync'
Hi tom,
can u able to provide the link to use celery
Thanks
You should just run the same code to create tenant in celery task. That's all, no magic links for simple tasks. Tenant creation can be longer then request, that's why we are doing it as background task. You can't redirect user directly to not existent tenant, so you will need to implement some kind of waiting page, that will check with ajax calls, if Tenant
is ready, and when it's created redirect to it.
You should just run the same code to create tenant in celery task. That's all, no magic links for simple tasks. Tenant creation can be longer then request, that's why we are doing it as background task. You can't redirect user directly to not existent tenant, so you will need to implement some kind of waiting page, that will check with ajax calls, if
Tenant
is ready, and when it's created redirect to it.
Sorry I went out for Vacation thanks for your reply
@tomturner
I populate my database using celery with a couple of signals. The signal are called 'post_schema_sync' and 'post_schema_sync'
I am curious to know the flow of signals and celery to perform database operations. Since celery tasks are bound before the apps are loaded, database operations on models are not allowed. How do you bind them?
Thanks
Hi,
I need to redirect and populate after successful login for the user to be directed their own tenant. please provide what to do next to redirection and populate the particular tenant.
Thanks