Reputation: 2598
When I do python manage.py help
[myapp]
update_overall_score
update_periodic_score
my custom command is listed, in which I can able to run update_periodic_score
through python manage.py update_periodic_score
but when I try the other one, I get the Unknown command: 'update_overall_score'
error.
What would be the problem? Both the files are placed in myapp/management/commands
directory with __init__.py
in all the directories.
This is my update_overall_score.py,
from django.core.management.base import BaseCommand, CommandError
from myapp.models import Users
class Command(BaseCommand):
"""
Updates the overall_score field of every user.
"""
def handle(self, *args, **options):
all_users = Users.objects.all()
try:
for user in all_users:
likes = user.likes_received.count()
stars = user.stars_received.count()
user.overall_score = likes + stars
user.save()
except Exception, e:
print e
return
print "Updated Overall Score."
return
Upvotes: 3
Views: 8913
Reputation: 2793
I had the same exact problem. After a few hours of searching through manage.py code it showed up that this was caused by my settings file configurations. I was using Mezzanine as my CMS. When you use it Mezzanine kind of says that you can put some apps under OPTIONAL_APPS variable, so I had my custom app under this variable but not in INSTALLED_APPS. Moved back to INSTALLED_APPS and everything started working as expected.
Make sure you have your application nowhere else than under INSTALLED_APPS. manage.py looks exactly to this constant.
Upvotes: 6