@staticmethod<EOL><INDENT>def validate_username(username):<DEDENT>
try:<EOL><INDENT>validate_slug(username)<EOL><DEDENT>except ValidationError:<EOL><INDENT>username = slugify(username)<EOL><DEDENT>user_model_cls = get_user_model()<EOL>_username = username<EOL>while user_model_cls.objects.filter(username=_username).exists():<EOL><INDENT>_username = '<STR_LIT>'.format(username, random.randint(<NUM_LIT:1>, <NUM_LIT:100>))<EOL><DEDENT>return _username<EOL>
This validation step is done when we are sure the user
does not exit on the systems and we need to create a new user.