Source code for django_tenant_options.management.commands.listoptions
"""Command to list all of the project's Options."""importloggingfromdjango.core.management.baseimportBaseCommandlogger=logging.getLogger("django_tenant_options")
[docs]classCommand(BaseCommand):"""Lists all of the project's Options that are active (not soft-deleted)."""help="Lists all of the project's Options that are active (not soft-deleted)."
[docs]deflistoptions(self):"""List all of the project's Options that are active (not soft-deleted)."""fromdjango_tenant_options.helpersimportall_option_subclassestry:model_subclasses=all_option_subclasses()ifnotmodel_subclasses:self.stdout.write(self.style.NOTICE("No options found in the project."))returnforModelClassinall_option_subclasses():# pylint: disable=C0103self.stdout.write(self.style.NOTICE(f"Model: {ModelClass.__name__}"))self.stdout.write(self.style.WARNING(" Options:"))foroptioninModelClass.objects.active():ifoption.tenantisnotNone:self.stdout.write(f" - {option.name} (Tenant: {option.tenant})")else:self.stdout.write(f" - {option.name}")self.stdout.write("")exceptExceptionase:# pylint: disable=W0703logger.error("Error: %s",e)
[docs]defhandle(self,*args,**kwargs):# pylint: disable=W0613"""Handle the command."""self.listoptions()