2

Following is a custom command I have written in following file myapp/management/commands/create_myadmin.py

from django.core.management.base import BaseCommand
from django.contrib.auth.models import User

class Command(BaseCommand):
    help = 'Creates a superuser that can view the admin page'

    def handle(self, *args, **options):
        try:
            user = User.objects.get(username='myadmin')
        except User.DoesNotExist:
            user = User.objects.create_superuser('myadmin', 'myadmin@mymail.com', 'myadmin')
            user.save()

After this, I added myapp into INSTALLED_APPS in myproject/settings.py

My problem is that when I use autocomplete feature and list down commands starting with "create", it doesn't show help string against create_myadmin as shown below

python3 manage.py create (pressed tab here)

createcachetable   -- creates table for SQL cache backend
createsuperuser    -- create a superuser
create_admin_user (help string missing??)

I expected the string stored in help variable to be visible here. Any quick pointers?

Update: I checked code for django/core/management/commands/createcachetable.py and the help text mentioned there doesn't match what I got above. Any idea where can one define the help text shown in above autocomplete?

Udi
  • 29,222
  • 9
  • 96
  • 129
comiventor
  • 3,922
  • 5
  • 50
  • 77
  • strange, I don't see any help strings on autocomplete, only a list of possible commands. Is this a django 1.10-feature, maybe? (I have python3.4 and django 1.9.12) – Ilja Mar 04 '17 at 18:34
  • can't you just do a search in the whole virtualenv for the string "creates table for SQL cache backend"? I don't think there will be many hits :) – Ilja Mar 04 '17 at 18:36
  • @Ilja I already did that before posting here and didn't get any results – comiventor Mar 04 '17 at 19:14
  • wow, nowhere in the whole python files? this is a miracle! :) (are you sure the search is correct, have you tried finding a string that you know is definitely there?). Anyway, sorry for my spamming, I don't have any notion here :) – Ilja Mar 04 '17 at 19:35
  • grep -irn "creates table for SQL cache backend" ~/.virtualenvs/myvenv/ and grep -irn "creates table for SQL cache backend" /usr/local/lib/python3.5/site-packages – comiventor Mar 04 '17 at 19:38
  • I don't get the detailed list of autocomplete options you get. Maybe dig into https://github.com/django/django/blob/master/extras/django_bash_completion to figure out how the list is built? – Laurent S Mar 05 '17 at 07:44
  • I am using Django1.10.3 and Python 3.5.2 – comiventor Mar 05 '17 at 15:51

1 Answers1

0

Django's bash and zsh completions run

./manage.py 

to get a list of commands. This list does not show help text. This makes sense, since showing the help text would require importing all of the command modules.

Django's zsh completion includes some default help messages for built in commands.

Udi
  • 29,222
  • 9
  • 96
  • 129