TitanFighter TitanFighter - 3 months ago 18
Python Question

How to correctly override Django manage.py's command?

I need to override

createsuperuser.py
's
handle
method in Django
Command
class.

I created myapp\management\commands\createsuperuser.py:

import getpass
import sys

import django.contrib.auth.management.commands.createsuperuser as makesuperuser

from django.contrib.auth.management import get_default_username
from django.contrib.auth.password_validation import validate_password
from django.core import exceptions
from django.core.management.base import CommandError
from django.utils.encoding import force_str
from django.utils.text import capfirst

class Command(makesuperuser.Command):
def handle(self, *args, **options):
# the rest of code is copied from Django source and is almost
# standart except few changes related to how info of
# REQUIRED_FIELDS is shown


When I do in terminal
./manage.py createsuperuser
I do not see any changes. If I change the name of my file to lets say
mycmd.py
and do
./manage.py mycmd
everything starts to work as I expect.

How to get changes I need using
./manage.py createsuperuser
?

Answer

Put your application name on top in the INSTALLED_APPS list.

Comments