私がする時python manage.py help
[myapp]
update_overall_score
update_periodic_score
私のカスタムコマンドがリストされていて、実行できますが、update_periodic_score
別のコマンドpython manage.py update_periodic_score
を試すとUnknown command: 'update_overall_score'
エラーが発生します。
問題は何でしょうか?両方のファイルは、すべてのディレクトリ内のmyapp/management/commands
ディレクトリに配置されます。__init__.py
これは私の 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