pythondjangoshelldjango-tenants

django-tenants: Python shell with specific tenant


I want to use "./manage.py shell" to run some Python commands with a specific tenant, but the code to do so is quite cumbersome because I first have to look up the tenant and then use with tenant_context(tenant)): and then write my code into this block.

I thought that there should be a command for that provided by django-tenants, but there isn't.


Solution

  • I've just looked at this myself and this will work, where tenant1 is your chosen tenant:

    python3 manage.py tenant_command shell --schema=tenant1