Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#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 Tim Graham, 7 years ago

Component: UncategorizedDocumentation
Summary: howto handle different apps with same custom management command names?Document how to override management commands
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

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.

comment:2 by stephanm, 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 Tim Graham, 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 Joe Krzystan, 7 years ago

Owner: changed from nobody to Joe Krzystan
Status: newassigned

I'll update the documentation to detail current behavior.

Version 0, edited 7 years ago by Joe Krzystan (next)

comment:5 by Joe Krzystan, 7 years ago

Has patch: set

comment:6 by Tim Graham <timograham@…>, 7 years ago

Resolution: fixed
Status: assignedclosed

In 48d92fe:

Fixed #28367 -- Doc'd how to override management commands.

comment:7 by Tim Graham <timograham@…>, 7 years ago

In f9db06cf:

[1.11.x] Fixed #28367 -- Doc'd how to override management commands.

Backport of 48d92fea672928b4571ddaab03667e74671391c0 from master

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