class FormClass:
username = ...
def clean(self):
super(FormClass, self).clean()
username = self.cleaned_data['username']
if User.objects.exclude(pk=self.instance.pk).filter(username=username).exists():
raise forms.ValidationError(f'Username "{username}" is already in use.')
return username