Fixed createsuperuser init command
This commit is contained in:
parent
35c7265bff
commit
49c84f13a8
|
@ -1,7 +1,7 @@
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model, base_user
|
||||||
from django.core.exceptions import FieldError
|
from django.core.exceptions import FieldError
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
@ -19,9 +19,14 @@ def create_initial_superuser(**kwargs):
|
||||||
)
|
)
|
||||||
from ..models import Account
|
from ..models import Account
|
||||||
try:
|
try:
|
||||||
Account.systemusers.field.related.model.objects.filter(account_id=1).exists()
|
Account.systemusers.field.model.objects.filter(account_id=1).exists()
|
||||||
except FieldError:
|
except FieldError:
|
||||||
# avoid creating a systemuser when systemuser table is not ready
|
# avoid creating a systemuser when systemuser table is not ready
|
||||||
Account.save = models.Model.save
|
Account.save = models.Model.save
|
||||||
|
old_init = base_user.AbstractBaseUser.__init__
|
||||||
|
def remove_is_staff(*args, **kwargs):
|
||||||
|
kwargs.pop('is_staff', None)
|
||||||
|
old_init(*args, **kwargs)
|
||||||
|
base_user.AbstractBaseUser.__init__ = remove_is_staff
|
||||||
manager = sys.argv[0]
|
manager = sys.argv[0]
|
||||||
execute_from_command_line(argv=[manager, 'createsuperuser'])
|
execute_from_command_line(argv=[manager, 'createsuperuser'])
|
||||||
|
|
Loading…
Reference in New Issue