In my django app I am writing a custom management command which will create an instance of an object based on the args passed and have the option of saving it to the database based on whether an option --save
is passed or not.
I've got a lot of help on this from the django documentation itself. Have also got important pointers from here about how to pass multiple arguments and here about how to have options.
from optparse import make_option
class Command(BaseCommand):
option_list = BaseCommand.option_list + (
make_option('--delete',
action='store_true',
dest='delete',
default=False,
help='Delete poll instead of closing it'),
)
def handle(self, *args, **options):
# ...
if options['delete']:
poll.delete()
# ...
However I am not able to find a detailed explanation of the fields in make_option. For example optparse.make_option lists
Instance attributes:
_short_opts : [string]
_long_opts : [string]
action : string
type : string
dest : string
default : any
nargs : int
const : any
choices : [string]
callback : function
callback_args : (any*)
callback_kwargs : { string : any }
help : string
metavar : string
In this help
is self explanatory and I figured out what dest
would mean, but I'm not clear what action='store_true'
means. In fact it'd be great if someone could give me a short description of what all the arguments to make_option
mean...
Thanks a lot