Dynavera/apps/accounts/management/commands/reset_passwords.py
2026-03-08 13:10:49 +00:00

17 lines
No EOL
618 B
Python

from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand
User = get_user_model()
class Command(BaseCommand):
help = 'Resets non-admin account passwords to "password" and admin account passwords to "admin"'
def handle(self, *args, **kwargs):
users = User.objects.all()
for user in users:
if user.is_staff:
user.set_password('admin')
else:
user.set_password('password')
user.save()
self.stdout.write(self.style.SUCCESS(f"Successfully updated {users.count()} users."))