Skip to content

Instantly share code, notes, and snippets.

@sjsakib
Last active November 5, 2017 06:08
Show Gist options
  • Save sjsakib/0a76789eece006f56712639bf3aa01c9 to your computer and use it in GitHub Desktop.
Save sjsakib/0a76789eece006f56712639bf3aa01c9 to your computer and use it in GitHub Desktop.
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