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