Last active
November 5, 2017 06:08
-
-
Save sjsakib/0a76789eece006f56712639bf3aa01c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
from myapp.models import UserProfile | |
class Command(BaseCommand): | |
help = 'Update points of all users' # help text | |
def handle(self, *args, **options): | |
for user in UserProfile.objects.all(): | |
points = 0 | |
for problem in user.solved_list.all(): | |
points += problem.type.points | |
user.points = points | |
self.stdout.write(self.style.SUCCESS('new points of '+str(user)+': '+str(points))) | |
user.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment