()
Creates admin users if needed.
Creates admin users if needed.
Creates admin users if needed .
def init_users():
    """
    Creates admin users if needed.
    """
    from .models import User, Profile

    for name, email in settings.ADMINS:
        user = User.objects.filter(email=email).first()
        if not user:
            user = User.objects.create(first_name=name, email=email, is_superuser=True, is_staff=True)
            User.objects.filter(pk=user.pk).update(username=f'admin-{user.pk}')
            # Reload to update state that signals may change.
            user = User.objects.filter(pk=user.pk).first()
            user.set_password(settings.DEFAULT_ADMIN_PASSWORD)

            user.save()

            text = "Admin user created automatically on startup."
            Profile.objects.filter(user=user).update(name=name, text=text, html=text)
            logger.info(f"Creating admin user: {user.email}")
        else:

            User.objects.filter(pk=user.pk).update(is_superuser=True, is_staff=True)
            # You might want to reapply the default ADMIN password on migration.
            # This will log out the user from their current session.
            #user.set_password(settings.DEFAULT_ADMIN_PASSWORD)
            #user.save()

            #logger.info(f"Resetting password for admin user: {user.email}, {user.username}")
            logger.info(f"Admin user: {user.email} already exists")
            pass
def init_users ( ) : from . models import User , Profile for name , email in settings . ADMINS : user = User . objects . filter ( email = email ) . first ( ) if not user : user = User . objects . create ( first_name = name , email = email , is_superuser = True , is_staff = True ) User . objects . filter ( pk = user . pk ) . update ( username = f'admin-{user.pk}' ) # Reload to update state that signals may change. user = User . objects . filter ( pk = user . pk ) . first ( ) user . set_password ( settings . DEFAULT_ADMIN_PASSWORD ) user . save ( ) text = "Admin user created automatically on startup." Profile . objects . filter ( user = user ) . update ( name = name , text = text , html = text ) logger . info ( f"Creating admin user: {user.email}" ) else : User . objects . filter ( pk = user . pk ) . update ( is_superuser = True , is_staff = True ) # You might want to reapply the default ADMIN password on migration. # This will log out the user from their current session. #user.set_password(settings.DEFAULT_ADMIN_PASSWORD) #user.save() #logger.info(f"Resetting password for admin user: {user.email}, {user.username}") logger . info ( f"Admin user: {user.email} already exists" ) pass