How to create a global management command?

100 views
Skip to first unread message

bwv549

unread,
Oct 27, 2015, 5:40:36 PM10/27/15
to Django users
I have some commands I'd like to include in the manage command (i.e., like 'coverage').  How to make a global command?  (I've written many commands for apps, but wonder how to make one that isn't tied to any app).

Carl Meyer

unread,
Oct 27, 2015, 5:45:51 PM10/27/15
to django...@googlegroups.com
Hi,
You can't. Management commands are always tied to an app.

That said, many people have an overly-narrow view of what an "app" must
be. A Django "app" can be any Python package at all that you include a
reference to in your INSTALLED_APPS setting. It doesn't need to have
models, or urls, or views. For instance, I often list my top-level
project package in INSTALLED_APPS as an "app", just so I can put e.g.
management commands or template tags there, if they are really
project-wide utilities that don't naturally fit in any sub-package/app.

Note of course that which app contains a management command has no
practical effect on its use (except when it comes to overriding
management commands and the ordering of `INSTALLED_APPS`).

Carl

signature.asc

Scot Hacker

unread,
Oct 28, 2015, 11:32:46 AM10/28/15
to Django users
Right - even though a management command must live inside of an app, all of them work "globally" across the project.  I often include an app called "base" in my projects for just this purpose - it includes management commands and utility functions that don't  belong logically to any other app.

./s
Reply all
Reply to author
Forward
0 new messages