def users_iterator():
    for i in range(nusers):
        is_superuser = i == 0
user = User(first_name='First' + str(i), is_staff=is_superuser,
    is_superuser=is_superuser, last_name='Last' + str(i), username='user' +
    str(i))
user.set_password('asdfqwer')
yield user


class Command(BaseCommand):

    def handle(self, **options):
        User.objects.bulk_create(iter(users_iterator()))
How to create a user in Django?