#28367 closed Cleanup/optimization (fixed)
Document how to override management commands
Reported by: | stephanm | Owned by: | Joe Krzystan |
---|---|---|---|
Component: | Documentation | Version: | 1.11 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
I have one question where I didn't find the answer in the docs.
If I have two django apps:
- app1
- app2
and both apps have lets say a custom management command called:
- importdata
Actually I do the following:
In every app I prepend the custom command name with the app name,
so in my case the custom commands would be named:
- app1_importdata (for app1)
- app2_importdata (for app2)
But what is the official "correct" way?
Does there exist some sort of namespace like:
- app1.importdata
- app2.importdata
or it is planned (in Django 2.x)?
If I have two external apps not programmed by myself
and both have one same-named management command...
how do I solve the problem?
Change History (7)
comment:1 by , 7 years ago
Component: | Uncategorized → Documentation |
---|---|
Summary: | howto handle different apps with same custom management command names? → Document how to override management commands |
Triage Stage: | Unreviewed → Accepted |
Type: | Uncategorized → Cleanup/optimization |
comment:2 by , 7 years ago
OK, so I did the right thing in my projects.
But one question remains:
What should I do if some day I need a django app
from pypi which has the same management commands?
(... or more than one django app from pypi where
all of them have management command names collisions)
comment:3 by , 7 years ago
You could alias the overridden command by creating a new management command in your project and importing the overridden command there so that it's accessible under a different name.
comment:4 by , 7 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
Submitted https://github.com/django/django/pull/8941
Details current behavior and methods by which commands can be overridden and accessed if overridden.
comment:5 by , 7 years ago
Has patch: | set |
---|
You need to use unique command names -- there's no notion of namespacing, though this was suggested in #27189, I don't think there was an follow up on that idea.
I'll classify this as a documentation ticket for explaining how to override management commands. There's a brief discussion on StackOverflow which could be a useful starting point in writing some docs.