check if username exists in database django

Solutions on MaxInterview for check if username exists in database django by the best coders in the world

showing results for - "check if username exists in database django"
Marta
03 Apr 2019
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
similar questions