Opened 17 years ago

Closed 17 years ago

#5516 closed (fixed)

Allow apps to provide their own commands

Reported by: Todd O'Bryan Owned by: Russell Keith-Magee
Component: Core (Management commands) Version: dev
Severity: Keywords: command
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

This patch allows users to create arbitrary commands in each app that can be invoked by django-admin.py.

Inside an app, users create a management.commands.my_command module for each command they'd like to add that must include a subclass of django.core.management.base.BaseCommand called Command. A command is invoked with app_name.my_command, where app_name is the path to the app provided in the INSTALLED_APPS setting.

Commands installed in this way are automatically plugged into the help system provided that the user has provided the Django settings correctly, either by using manage.py, setting the DJANGO_SETTINGS_MODULE environment variable, or by using the --settings option to django-admin.py.

Attachments (1)

user_commands.patch (8.1 KB ) - added by Todd O'Bryan 17 years ago.

Download all attachments as: .zip

Change History (6)

by Todd O'Bryan, 17 years ago

Attachment: user_commands.patch added

comment:1 by Todd O'Bryan, 17 years ago

Owner: changed from nobody to Todd O'Bryan

I accidentally uploaded the wrong patch. user_commands is correct. The other one can be deleted (and I would delete it if I knew how).

comment:2 by Adrian Holovaty, 17 years ago

I've deleted the erroneous attachment.

comment:3 by Antti Kaihola, 17 years ago

I like it. Great idea. So far I've written separate scripts to do various maintenance, verification or import tasks for the database. Each of those scripts has to repeat the same dance for setting up the environment, which manage.py would provide for free. I'll use this immediately if it makes it into Django.

in reply to:  3 comment:4 by Russell Keith-Magee, 17 years ago

Owner: changed from Todd O'Bryan to Russell Keith-Magee
Triage Stage: UnreviewedAccepted

Replying to akaihola:

I like it. Great idea.

Short version - this feature is coming, hopefully soon.

Long version - this idea has been approved for inclusion by the BFDLs, so it's just a matter of getting an implementation that works. I've made two attempts in the past, which both failed because of some nasty edge cases. I've had a quick look at this patch, and it looks promising. I'm hoping to have a look at it tonight.

comment:5 by Russell Keith-Magee, 17 years ago

Resolution: fixed
Status: newclosed

(In [6400]) Fixed #5516 -- Added the ability for applications to define their own management commands. Pieces of this patch taken from a contribution by Todd O'Bryan. Thanks Todd.

Note: See TracTickets for help on using tickets.
Back to Top