From 8a602d8d4b5e7d6181004e100d11403465f4fce2 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 29 Jun 2016 17:24:52 -0300 Subject: [PATCH] #38 valida username existente --- sigi/apps/usuarios/forms.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/sigi/apps/usuarios/forms.py b/sigi/apps/usuarios/forms.py index afe0797..b3a67ed 100644 --- a/sigi/apps/usuarios/forms.py +++ b/sigi/apps/usuarios/forms.py @@ -171,6 +171,15 @@ class UsuarioForm(ModelForm): raise ValidationError(msg) return True + def clean_username(self): + usuario = User.objects.filter( + username=self.cleaned_data[u'username']).exists() + + if usuario: + raise ValidationError(u'Usuário existente.') + + return self.cleaned_data + def clean_primeiro_numero(self): cleaned_data = self.cleaned_data