from django.core.exceptions import ValidationError from users.models import User, Player def usernameValidator(username): if User.objects.filter(username__iexact=username).first() is not None: raise ValidationError("Sorry, deze gebruikersnaam is al in gebruik")