Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR TYPESCRIPT

check if username exists in database django

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #check #username #exists #database #django
ADD COMMENT
Topic
Name
2+7 =