Howto to create custom admin commands with subcommands

35 views
Skip to first unread message

anton

unread,
Sep 19, 2016, 6:14:17 PM9/19/16
to django...@googlegroups.com
Hi,

is there an possibility to use
https://docs.python.org/3/library/argparse.html#sub-commands

in the custom admin commands so I can have subcommands like

manage.py mycommand subcommand1 choice1-for-subcommand1
manage.py mycommand subcommand1 choice2-for-subcommand1
manage.py mycommand subcommand2 variable-param


Preferably an official way.

I tested an example which I found in the internet
(forgot where), it worked in python 2.7 but didn't in python 3.5
(even when using the same django 1.10 base)

Derek

unread,
Sep 21, 2016, 4:25:42 AM9/21/16
to Django users, ant...@gmx.de
Sorry, I have not done this, but if you look at this section:
https://docs.djangoproject.com/en/1.10/howto/custom-management-commands/#accepting-optional-arguments
then at the end there is a link from the word "argparse" to this site:
https://docs.python.org/3/library/argparse.html#module-argparse
which deals with sub-commands.  So that implies it should be possible. (assuming you are working with the Python 3 release of Django)
Reply all
Reply to author
Forward
0 new messages