Customizing UserCreationForm for email address as username in Django 1.2 -
django 1.2 adds new allowable symbols usernames, meaning usernames can email addresses. until have been using inbuilt usercreationform registration - how can alter label 'username' field 'email' field? , how add (but still user object) fields such first , last names? (and how make them optional?)
should altering usercreationform extent or better starting scratch (and if latter, how?)
thanks.
to change label of email field, can subclass usercreationform
follows
from django import forms django.utils.translation import ugettext_lazy _ django.contrib.auth.forms import usercreationform class myusercreationform(usercreationform): username = forms.regexfield(label=_("email"), max_length=30, regex=r'^[\w.@+-]+$', help_text = _("required. 30 characters or fewer. letters, digits , @/./+/-/_ only."), error_messages = {'invalid': _("this value may contain letters, numbers , @/./+/-/_ characters.")})
adding first_name , last_name fields not quite easy, because form's save method takes username, email , password. 2 possibilities are:
- override form's save method
- display userchangeform once user has been created (this django admin app does)
Comments
Post a Comment