Last active
June 26, 2020 13:28
-
-
Save craiga/2f64f8d40b8681f9ad6d9297262b17a5 to your computer and use it in GitHub Desktop.
Django Command Boilerplate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Command to do something.""" | |
import logging | |
from django.core.management.base import BaseCommand | |
logger = logging.getLogger(__name__) | |
class Command(BaseCommand): | |
"""Do something.""" | |
help = __doc__ | |
def handle(self, *args, **options): | |
"""Handle a call to the command.""" | |
# Set logging level. | |
# 0 = minimal output, 1 = normal output, 2 = verbose output, and | |
# 3 = very verbose output. | |
verbosity = options['verbosity'] | |
log_levels = (logging.ERROR, | |
logging.WARNING, | |
logging.INFO, | |
logging.DEBUG) | |
logger.setLevel(log_levels[verbosity]) | |
# TODO: Something. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://docs.djangoproject.com/en/stable/howto/custom-management-commands/