[Fixed]-Modifying Django Command argument

1👍

You could use a class attribute:

class Command(object):
    help = 'roll over and die'
    foo_required = True

    def add_arguments(self, parser):
        parser.add_argument(
            '--foo',
            # ...
            required=self.foo_required
        )

and then in inheriting Command:

class Command(foo.bar.Command):
    foo_required = False

and you wouldn’t have to override add_arguments.

Leave a comment