django-orchestra/orchestra/apps/accounts/management/commands/createsuperuser.py

15 lines
533 B
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from django.contrib.auth import get_user_model
from django.contrib.auth.management.commands import createsuperuser
from orchestra.apps.accounts.models import Account
class Command(createsuperuser.Command):
def handle(self, *args, **options):
super(Command, self).handle(*args, **options)
users = get_user_model().objects.filter()
if len(users) == 1 and not Account.objects.all().exists():
user = users[0]
user.account = Account.objects.create(user=user)
user.save()