Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from django import forms
- from matab.models import careunit
- from django.contrib.auth.models import User
- from django.contrib.auth.forms import UserCreationForm
- from django.utils.translation import ugettext as _, ugettext_lazy
- # Create your models here.
- class createaccountform(forms.ModelForm):
- username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
- help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
- error_messages = {'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
- password1 = forms.CharField(label=ugettext_lazy(u"Password"), widget=forms.PasswordInput, required=True)
- password2 = forms.CharField(label=ugettext_lazy(u"Password confirmation"), widget=forms.PasswordInput,
- help_text = ugettext_lazy(u"Enter the same password as above, for verification."))
- name = forms.CharField(label=ugettext_lazy(u"Name"), widget=forms.TextInput, required=True)
- class Meta:
- model = User
- fields = ("username", "first_name", "last_name", "email")
- def save(self, commit=False):
- password = self.cleaned_data["password1"]
- user = super(createaccountform, self).save(commit=False)
- user.set_password(password)
- user.save()
- careunit = careunit()
- careunit.name = self.cleaned_data["name"]
- careunit.phonenumber = self.cleaned_data["phonenumber"]
- careunit.mobilenumber = self.cleaned_data["mobilenumber"]
- careunit.username = user
- careunit.save()
- return user
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement