custom management commands: AttributeError: 'module' object has no attribute 'Command'

1,300 views
Skip to first unread message

Matthew Meyer

unread,
Aug 10, 2012, 8:14:55 PM8/10/12
to django...@googlegroups.com

I am trying to make a custom management command as show in the docs here: https://docs.djangoproject.com/en/dev/howto/custom-management-commands/

When I try to run the command from my project directory I am experiencing the following error:

AttributeError: 'module' object has no attribute 'Command'

Here is the file:

#event_expiration.py
from django.core.management.base import BaseCommand, CommandError
from app.models import Event
import datetime

class Command(BaseCommand):
    help
= 'deletes expired events'

   
def handle(self, *args, **options):

        today
= datetime.datetime.now()
        events
= Event.objects.filter(date=datetime.date(2011,11,11))

       
for e in events:
            e
.delete()

       
self.stdout.write('Expired events successfully deleted.')

The command I am running is :

$ python manage.py event_expiration

I've made sure I am adding the event_expiration.py file within management and commands folders and that those folders have init files. those are in one of my app folders.

Am I overlooking something here? Any help is appreciated, thanks!

Melvyn Sopacua

unread,
Aug 12, 2012, 4:44:06 AM8/12/12
to django...@googlegroups.com
On 11-8-2012 2:14, Matthew Meyer wrote:

> The command I am running is :
>
> $ python manage.py event_expiration
>
> I've made sure I am adding the event_expiration.py file within management
> and commands folders and that those folders have init files. those are in
> one of my app folders.
>
> Am I overlooking something here? Any help is appreciated, thanks!

Since I don't see anything wrong with your code or setup, I'm going to
take a stab in the dark and say that you need to loose the underscore in
the command.
Otherwise, please provide the *full* traceback for more clues.

--
Melvyn Sopacua

creecode

unread,
Aug 13, 2012, 2:31:08 PM8/13/12
to django...@googlegroups.com
I have many custom management command names that have underscores in them.  I've never had a problem.  I believe that a management command name only needs follow python rules for naming files.


On Sunday, August 12, 2012 1:44:06 AM UTC-7, Melvyn Sopacua wrote:

On 11-8-2012 2:14, Matthew Meyer wrote:

Since I don't see anything wrong with your code or setup, I'm going to
take a stab in the dark and say that you need to loose the underscore in
the command.

Toodle-looooooooooo................
creedcode 

Kurtis Mullins

unread,
Aug 13, 2012, 2:47:02 PM8/13/12
to django...@googlegroups.com
I'd look more into the full traceback. I haven't had any trouble with underscores either. 

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/IyKV_xgNgOcJ.

To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

Reply all
Reply to author
Forward
0 new messages