2

I'm working with django 1.7 and i have created this management command:

File structure:

app/
    __init__.py
    management/
               __init__.py
               commands/
                        __init__.py
                        modal_asign.py

Code:

from django.core.management.base import BaseCommand, CommandError
from webinar.models import Webinar

class Commands(BaseCommand):

    help = 'Assign modal link to every webinar'

    def handle(self):
        latest_webinar = Webinar.objects.all().order_by('-webinar_date')[0]
        for webinars in latest_webinar:
            print "http://webinar.academiaa2.com/webinars/#displayModal" + webinars

and i'm getting this error when trying to test it with python manage.py modal_asign

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 377, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 238, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/rafael/venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 42, in load_command_class
    return module.Command()
AttributeError: 'module' object has no attribute 'Command'

1 Answer 1

7

Your class name is called Commands, whereas django expects it to be called Command. Hence the error.

Change

class Commands(BaseCommand):

to

class Command(BaseCommand):
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.