Actually, in this case, it gets even easier!  There's no need to run an 
external command.  You can call a management command in-process:

from django.core.management import call_command

...

    call_command(
        'createsuperuser', username=ADMIN_USER, email='[email protected]',
        noinput=True)

And then you can just trust that that has created the superuser you wanted.  No 
need to catch exceptions or use get_or_create.  If the superuser hasn't been 
created, you're more likely to want to know about it than to want to proceed 
oblivious.  (Or if you're guarding against some specific known problem, 
document it in the code!)
-- 
https://code.launchpad.net/~matsubara/maas/packaging-tests/+merge/123630
Your team MAAS Maintainers is requested to review the proposed merge of 
lp:~matsubara/maas/packaging-tests into lp:~maas-maintainers/maas/packaging.

_______________________________________________
Mailing list: https://launchpad.net/~launchpad-reviewers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~launchpad-reviewers
More help   : https://help.launchpad.net/ListHelp

Reply via email to