Last active
November 5, 2017 06:47
-
-
Save sjsakib/ce7099bc18a6e480ef3b6a1a79f7f680 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 add_arguments(self, parser): # it takes a `parser` as an argument | |
| parser.add_argument('-s', action='store_true', help='silent') | |
| 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 | |
| if not options['s']: # We have all our argumets in the options dict | |
| self.stdout.write(self.style.SUCCESS(str(user)+' new points: '+str(points))) | |
| user.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment