Boas Caros,
Estou a ter erro abaixo. Não consigo identifica qual a causa.
File "C:\django\connectedin\usuarios\views.py", line 20, in post
if form.is_valid():
File "C:\django\connectedin\usuarios\forms.py", line 20, in is_valid
user_exists = User.objects.filter(username=self.data['nome'].exists())
AttributeError: 'str' object has no attribute 'exists'
[14/Apr/2018 18:00:08] "POST /registar/ HTTP/1.1" 500 80788
Aqui o meu forms:
from django import forms
from django.contrib.auth.models import User
class RegistarUsuarioForm(forms.Form): # Gerdar de forms.Form
#Classe RegistarUsuarioForm
nome = forms.CharField(required=True)
email = forms.EmailField(required = True)
senha = forms.CharField(required=True)
telefone = forms.CharField(required=True)
empresa = forms.CharField(required=True)
#Sobrescrever método is_valid do forms.Form
def is_valid (self):
valid = True
if not super(RegistarUsuarioForm, self).is_valid():
self.adiciona_erro('Por fvaor, verifica os dados informados')
valid = False
user_exists = User.objects.filter(username=self.data['nome'].exists())
#Verificar se o usuario existe
if user_exists:
self.adiciona_erro('Usuário já existe')
valid = False
return valid
def adiciona_erro(self, message):
erros = self._errors.setdefault(forms.forms.NON_FIELD_ERRORS, forms.utils.ErrorList())
erros.append(message)