Django

Code

Ticket #5516 (closed: fixed)

Opened 10 months ago

Last modified 10 months ago

Allow apps to provide their own commands

Reported by: toddobryan Assigned to: russellm
Milestone: Component: django-admin.py
Version: SVN Keywords: command
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

user_commands.patch (8.1 kB) - added by toddobryan on 09/16/07 17:41:11.

Change History

09/16/07 17:41:11 changed by toddobryan

  • attachment user_commands.patch added.

09/16/07 17:48:49 changed by toddobryan

  • owner changed from nobody to toddobryan.
  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

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).

09/16/07 19:13:02 changed by adrian

I've deleted the erroneous attachment.

(follow-up: ↓ 4 ) 09/17/07 15:58:12 changed by akaihola

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 ) 09/17/07 18:42:48 changed by russellm

  • owner changed from toddobryan to russellm.
  • stage changed from Unreviewed to Accepted.

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.

09/21/07 11:19:20 changed by russellm

  • status changed from new to closed.
  • resolution set to fixed.

(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.


Add/Change #5516 (Allow apps to provide their own commands)




Change Properties
Action