From f944b224e9b347faf8b83b987a0296f4f5024236 Mon Sep 17 00:00:00 2001 From: Serghei MIHAI Date: Tue, 24 Jun 2014 14:07:19 +0200 Subject: [PATCH 2/2] management command for listing tenants --- .../management/commands/list_tenants.py | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 entrouvert/djommon/multitenant/management/commands/list_tenants.py diff --git a/entrouvert/djommon/multitenant/management/commands/list_tenants.py b/entrouvert/djommon/multitenant/management/commands/list_tenants.py new file mode 100644 index 0000000..6719f1c --- /dev/null +++ b/entrouvert/djommon/multitenant/management/commands/list_tenants.py @@ -0,0 +1,27 @@ +from django.core.management.base import BaseCommand, CommandError +from optparse import make_option + +class Command(BaseCommand): + requires_model_validation = True + can_import_settings = True + option_list = BaseCommand.option_list + ( + make_option('--list-settings', + action='store_true', + default=False, + help='List settings'), + ) + + def handle(self, **options): + + import tenant_schemas.utils + + TenantModel = tenant_schemas.utils.get_tenant_model() + all_tenants = TenantModel.objects.all() + + if not all_tenants: + raise CommandError("""There are no tenants in the system. + To learn how create a tenant, see: + https://django-tenant-schemas.readthedocs.org/en/latest/use.html#creating-a-tenant""") + + schemas = ((t.schema_name, t.domain_url,) for t in all_tenants) + print('\n'.join(["%s : %s" % schema for schema in schemas])) -- 2.0.0