dj22: disable subparsers work around (#51516)
This commit is contained in:
parent
7df6f0ae0c
commit
48f52ae9ba
|
@ -21,6 +21,7 @@ from __future__ import unicode_literals
|
|||
from decimal import Decimal
|
||||
import datetime
|
||||
|
||||
import django
|
||||
from django.core.management.base import BaseCommand, CommandParser
|
||||
from django.utils.six import python_2_unicode_compatible
|
||||
from django.utils.timezone import now
|
||||
|
@ -68,11 +69,15 @@ class Command(BaseCommand):
|
|||
def add_arguments(self, parser):
|
||||
cmd = self
|
||||
|
||||
class SubParser(CommandParser):
|
||||
def __init__(self, **kwargs):
|
||||
super(SubParser, self).__init__(cmd, **kwargs)
|
||||
if django.VERSION < (2, 1):
|
||||
# https://stackoverflow.com/questions/36706220/is-it-possible-to-create-subparsers-in-a-django-management-command
|
||||
class SubParser(CommandParser):
|
||||
def __init__(self, **kwargs):
|
||||
super(SubParser, self).__init__(cmd, **kwargs)
|
||||
|
||||
subparser = parser.add_subparsers(dest='command', help='commands', parser_class=SubParser)
|
||||
subparser = parser.add_subparsers(dest='command', help='commands', parser_class=SubParser)
|
||||
else:
|
||||
subparser = parser.add_subparsers(title='subcommands', dest='command', required=True)
|
||||
find_parser = subparser.add_parser('find', help='find duplicates')
|
||||
find_parser.add_argument('--count', type=int, help='search last count persons created',
|
||||
default=None)
|
||||
|
|
Loading…
Reference in New Issue