📅  最后修改于: 2022-03-11 14:48:30.728000             🧑  作者: Mango
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