From 6709654e0471c49c13f8d448ee9162087551984a Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Thu, 28 May 2015 14:04:07 -0500 Subject: [PATCH] Create a default organization. --- .../management/commands/create_default_org.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 awx/main/management/commands/create_default_org.py diff --git a/awx/main/management/commands/create_default_org.py b/awx/main/management/commands/create_default_org.py new file mode 100644 index 0000000000..77eebfb3fa --- /dev/null +++ b/awx/main/management/commands/create_default_org.py @@ -0,0 +1,23 @@ +# Copyright (c) 2015 Ansible, Inc. +# All Rights Reserved + +from django.core.management.base import BaseCommand + +from awx.main.models import Organization + + +class Command(BaseCommand): + """Creates the default organization if and only if no organizations + exist in the system. + """ + help = 'Creates a default organization iff there are none.' + + def handle(self, *args, **kwargs): + # Sanity check: Is there already an organization in the system? + if Organization.objects.count(): + return + + # Create a default organization. + org, new = Organization.objects.get_or_create(name='Default') + if new: + print('Default organization added.')