django AttributeError: 'EmailField' object has no attribute 'attrs'

-1

here are my codes for forms.py

________________________
from django import forms
from .models import Account

class Usuario(forms.ModelForm):
    password=forms.PasswordInput()

    class Meta:
        model=Account
        fields=( 'email','username','first_name','last_name')
        widgets={
            'email':forms.EmailField()
        }


    def save(self, commit=True):
        user = super(Usuario, self).save(commit=False)
        user.set_password(self.cleaned_data["password"])
        user.save()
        return user
____________________________________________________________________
models.py
from django.db import models
from django.contrib.auth.models import AbstractBaseUser,BaseUserManager

# Create your models here.

class AccountManager(BaseUserManager):
    def create_user(self, email, password, **kwargs):
        if not email:
            raise ValueError('Users must have a valid email address.')

        if not kwargs.get('username'):
            raise ValueError('Users must have a valid username.')

        account = self.model(
            email=self.normalize_email(email), username=kwargs.get('username')
        )

        account.set_password(password)
        account.save()

        return account

    def create_superuser(self, email, password, **kwargs):
        account = self.create_user(email, password, **kwargs)

        account.is_admin = True
        account.is_staff=True
        account.save()

        return account
class Account(AbstractBaseUser):
    email = models.EmailField(unique=True,max_length=40)
    username = models.CharField(max_length=40, unique=True)

    first_name = models.CharField(max_length=40, blank=True)
    last_name = models.CharField(max_length=40, blank=True)


    is_admin = models.BooleanField(default=False)
    is_staff=models.BooleanField(default=False)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    objects = AccountManager()

    USERNAME_FIELD = 'email'
    REQUIRED_FIELDS = ['username']

    def __str__(self):
         return self.username


    def get_full_name(self):
        return ' '.join([self.first_name, self.last_name])


    def get_short_name(self):
        return self.first_name

    def has_perm(self ,perm, obj=None):
        "Does the user have a specific permission?"
        # Simplest possible answer: Yes, always
        return True

    def has_module_perms(self, perm, obj=None):
        "Does the user have a specific permission?"
        # Simplest possible answer: Yes, always
        return True

    
asked by Kiyoshi ishikawa 22.09.2016 в 06:14
source

1 answer

1

Try with:

email = forms.EmailField(widget=forms.EmailInput())

Staying:

class Usuario(forms.ModelForm):
    email = forms.EmailField(widget=forms.EmailInput())
    password = forms.PasswordInput()

    class Meta:
        model = Account
        fields = ( 'email','username','first_name','last_name')
    
answered by 22.09.2016 в 10:13