How to create label_command ind django1.10

109 views Asked by At

I am moving to Django1.10 from django 1.6.11 (I know this is very old. But finally moving to latest version)

My management commands are breaking.

class Command(LabelCommand):
    label = 'filename'

    def add_arguments(self, parser):
        parser.add_argument('filename', nargs='+', type=str)

    def handle_label(self, filename, **options):
        print filename

Is this the correct way ? The above is not working as expected i.e.

1

There are 1 answers

0
7mp On

For me the following worked: change

parser.add_argument('filename', nargs='+', type=str)

to

parser.add_argument('args', metavar=self.label, nargs='+')

a line which I copied directly django/django/core/management/base.py when fixing my LabelCommands when migrating from 1.7 to 1.10.7.

Although what you might want to do is to add substitute the line above with

super(Command, self).add_arguments(parser)

to maintain forwards compatibility.