Name clashes on custom commands

12 views
Skip to first unread message

Tim Johnson

unread,
Apr 9, 2020, 6:18:54 PM4/9/20
to MLDjango
I have more of an observation than a question and it is likely that any
responses may serendipitously enlighten me.

From the contributions of good djangoists to an earlier query on my
part (subject ORM from the command line) I have been enlightened about
custom commands and django-extensions and I couldn't be happier about
having more tools in my kit.

I used the create_command subcommand to create a custom subcommand under
one app, called articles. It defaults as sample so I left it as such.
Tweaked it a bit to make it runnable and examined the output of 'python
manage.py help'. I could see there that 'sample' shows under the
[articles] header.

So, I repeated the create_command process to create a command under a
different app called pages. Again, the command is named 'sample.py' in
keeping with the default action.

I could then see 'sample' listed out under the [pages] heading and
indeed, that is the one and only command that is run.

My comment/question is : is there a way to resolve such command name
clashes? I saw no sign of an option that would allow associating like
names with different apps.

It is easy to resolve, of course: trivial example being
articles_sample.py and pages_sample.py

--
Tim
tj49.com

Andréas Kühne

unread,
Apr 10, 2020, 4:45:16 AM4/10/20
to django...@googlegroups.com
Hi Tim,

You need to make sure that your commands are unique in your project. Otherwise like you have discovered one overwrites the other. This is actually a good thing though - we use it in one of our projects to override the "runserver" command. The order of the applications in your project dictates which command is run.

Regards,

Andréas


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3c9455ae-ba2b-a3dd-a2b2-4306f1826160%40akwebsoft.com.

Tim Johnson

unread,
Apr 10, 2020, 2:04:16 PM4/10/20
to MLDjango

Ah. I see the logic of it. Similar to elisp, but different also.

Thank you

Reply all
Reply to author
Forward
0 new messages