I'm trying to setup a User - UserProfile relationship, display the form and save the data.
When submitted, the data is saved, except the password field doesn't get hashed.
Forms.py
class UserForm(forms.ModelForm):
username = forms.RegexField(label="Username", max_length=30, regex=r'^[\w.@+-]+$', help_text = "My text", error_messages = {'invalid': "This value may contain only letters, numbers and @/./+/-/_ characters."})
password = forms.CharField(label="Password", widget=forms.PasswordInput)
class Meta:
model = User
fields = ["first_name", "last_name", "username", "email", "password"]
def clean_username(self):
username = self.cleaned_data['username']
if not re.search(r'^\w+$', username):
raise forms.ValidationError('Username can contain only alphanumeric characters')
try:
User.objects.get(username=username)
except ObjectDoesNotExist:
return username
raise forms.ValidationError('Username is already taken')
class UserProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ['user_is']