Skip to content

Instantly share code, notes, and snippets.

Created Sep 13, 2022
What would you like to do?
# Get the users that have a name but don't have a username
users = User.objects.filter(username__isnull=True, name__isnull=False)
# For each user apply the transform to get the username.
# This doesn't hit the database
for user in users:
user.username =" ", "").lower()
# Hit the database
User.objects.bulk_update(users, ("username",))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment