def clean_username self name self cleaned_data username if User object

1
2
3
4
5
def clean_username(self):
name = self.cleaned_data['username']
if User.objects.filter(username=name):
raise forms.ValidationError("User with such name does already exist.")
return name