from .models import Account
class Usuario(forms.ModelForm):
password=forms.PasswordInput()
class Meta:
model=Account
fields=( 'email','username','first_name','last_name')
widgets={
}
def save(self, commit=True):
user = super(Usuario, self).save(commit=False)
user.set_password(self.cleaned_data["password"])
user.save()
return userfrom 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
from django.shortcuts import render
from django.views.generic import CreateView,TemplateView
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponse,HttpResponseRedirect
from .forms import Usuario
from .models import Account
# Create your views here.
class vista(TemplateView):
template_name='base.html'
#def get(self,request,*args,**kwargs):
# return render(request,self.template_name)
class Registro (CreateView):
form_class =Usuario
template_name = 'registro.html'
success_url = reverse_lazy('login:home')
Traceback (most recent call last):
File "/home/souma/Descargas/pycharm-2016.1.4/helpers/pycharm/django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "/usr/lib64/python3.4/runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.4/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/souma/PycharmProjects/untitled10/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/lib64/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/lib64/python3.4/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/lib64/python3.4/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/lib64/python3.4/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/lib64/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib64/python3.4/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib64/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib64/python3.4/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/souma/PycharmProjects/untitled10/untitled10/urls.py", line 21, in <module>
url(r'^',include('login.urls')),
File "/usr/lib64/python3.4/site-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/souma/PycharmProjects/untitled10/login/urls.py", line 3, in <module>
from login.views import vista, Registro
File "/home/souma/PycharmProjects/untitled10/login/views.py", line 5, in <module>
from .forms import Usuario
File "/home/souma/PycharmProjects/untitled10/login/forms.py", line 7, in <module>
class Usuario(forms.ModelForm):
File "/usr/lib64/python3.4/site-packages/django/forms/models.py", line 247, in __new__
opts.field_classes)
File "/usr/lib64/python3.4/site-packages/django/forms/models.py", line 172, in fields_for_model
formfield = f.formfield(**kwargs)
File "/usr/lib64/python3.4/site-packages/django/db/models/fields/__init__.py", line 1711, in formfield
return super(EmailField, self).formfield(**defaults)
File "/usr/lib64/python3.4/site-packages/django/db/models/fields/__init__.py", line 1120, in formfield
return super(CharField, self).formfield(**defaults)
File "/usr/lib64/python3.4/site-packages/django/db/models/fields/__init__.py", line 903, in formfield
return form_class(**defaults)
File "/usr/lib64/python3.4/site-packages/django/forms/fields.py", line 229, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/lib64/python3.4/site-packages/django/forms/fields.py", line 118, in __init__
widget.attrs.update(extra_attrs)
AttributeError: 'EmailField' object has no attribute 'attrs'
django 1.9.7
-- File "/home/souma/Descargas/pycharm-2016.1.4/helpers/pycharm/django_manage.py", line 41, in <module>
run_module(manage_file, None, '__main__', True)
File "/usr/lib64/python3.4/runpy.py", line 182, in run_module
return _run_module_code(code, init_globals, run_name, mod_spec)
File "/usr/lib64/python3.4/runpy.py", line 96, in _run_module_code
mod_name, mod_spec, pkg_name, script_name)
File "/usr/lib64/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/souma/PycharmProjects/untitled10/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/lib64/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/usr/lib64/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 398, in execute
self.check()
File "/usr/lib64/python3.4/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/usr/lib64/python3.4/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/usr/lib64/python3.4/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/usr/lib64/python3.4/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/usr/lib64/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib64/python3.4/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/usr/lib64/python3.4/site-packages/django/utils/functional.py", line 33, in __get__
res = instance.__dict__[self.name] = self.func(instance)
File "/usr/lib64/python3.4/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/souma/PycharmProjects/untitled10/untitled10/urls.py", line 21, in <module>
url(r'^',include('login.urls')),
File "/usr/lib64/python3.4/site-packages/django/conf/urls/__init__.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/usr/lib64/python3.4/importlib/__init__.py", line 109, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/home/souma/PycharmProjects/untitled10/login/urls.py", line 3, in <module>
from login.views import vista, Registro
File "/home/souma/PycharmProjects/untitled10/login/views.py", line 5, in <module>
from .forms import Usuario
File "/home/souma/PycharmProjects/untitled10/login/forms.py", line 7, in <module>
class Usuario(forms.ModelForm):
File "/usr/lib64/python3.4/site-packages/django/forms/models.py", line 247, in __new__
opts.field_classes)
File "/usr/lib64/python3.4/site-packages/django/forms/models.py", line 172, in fields_for_model
formfield = f.formfield(**kwargs)
File "/usr/lib64/python3.4/site-packages/django/db/models/fields/__init__.py", line 1711, in formfield
return super(EmailField, self).formfield(**defaults)
File "/usr/lib64/python3.4/site-packages/django/db/models/fields/__init__.py", line 1120, in formfield
return super(CharField, self).formfield(**defaults)
File "/usr/lib64/python3.4/site-packages/django/db/models/fields/__init__.py", line 903, in formfield
return form_class(**defaults)
File "/usr/lib64/python3.4/site-packages/django/forms/fields.py", line 229, in __init__
super(CharField, self).__init__(*args, **kwargs)
File "/usr/lib64/python3.4/site-packages/django/forms/fields.py", line 118, in __init__
widget.attrs.update(extra_attrs)
AttributeError: 'EmailField' object has no attribute 'attrs'
django 1.9.7
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/cade15ae-b45d-47ae-ba0f-289ae3e8c6ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment