Skip to content

Commit

Permalink
Merge pull request #274 from goodtune/list-tenants
Browse files Browse the repository at this point in the history
Added list_tenants management command
  • Loading branch information
bernardopires committed Aug 2, 2015
2 parents a2f1f6f + 77ef08e commit b3ebc39
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
13 changes: 13 additions & 0 deletions docs/use.rst
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ The command ``createsuperuser`` is already automatically wrapped to have a ``sch
./manage.py createsuperuser --username='admin' --schema=customer1
list_tenants
~~~~~~~~~~~~

Prints to standard output a tab separated list of schema:domain_url values for each tenant.

.. code-block:: bash
for t in $(./manage.py list_tenants | cut -f1);
do
./manage.py tenant_command dumpdata --schema=$t --indent=2 auth.user > ${t}_users.json;
done
Performance Considerations
--------------------------

Expand Down
17 changes: 17 additions & 0 deletions tenant_schemas/management/commands/list_tenants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import csv
import sys

from django.core.management import BaseCommand
from tenant_schemas.utils import get_tenant_model


class Command(BaseCommand):
def handle(self, *args, **options):
columns = ('schema_name', 'domain_url')

TenantModel = get_tenant_model()
all_tenants = TenantModel.objects.values_list(*columns)

out = csv.writer(sys.stdout, dialect=csv.excel_tab)
for tenant in all_tenants:
out.writerow(tenant)

0 comments on commit b3ebc39

Please sign in to comment.