मैं उपयोगकर्ता - उपयोगकर्ता प्रोफाइल संबंध स्थापित करने का प्रयास कर रहा हूं, फ़ॉर्म प्रदर्शित कर रहा हूं और डेटा को सहेज सकता हूं।Django, ModelForms, उपयोगकर्ता और UserProfile - हैशिंग पासवर्ड नहीं
सबमिट किए जाने पर, डेटा सहेजा गया है, को छोड़कर पासवर्ड फ़ील्ड को धोया नहीं जाता है।
Forms.py
class UserForm(forms.ModelForm):
username = forms.RegexField(label="Username", max_length=30,
regex=r'^[\[email protected]+-]+$', 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']