0

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.

Akamad007
  • 1,551
  • 3
  • 22
  • 38
  • The method should be named `handle`, not `handle_label`. It will be easier to upgrade to 1.8 LTS first, rather than skipping straight to 1.10. It's even worth testing with 1.7 to make sure you don't miss any depreciation warnings. – Alasdair Dec 13 '16 at 20:35
  • what you meant by `breaking` ?, can you give error you are getting ? – Renjith Thankachan Dec 14 '16 at 03:05

1 Answers1

1

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.

7mp
  • 119
  • 5