I'm halfway through a Django project and we did not start with the default Django User model that is provided. Now it is too late into the project to go back and implement the User model.
The user I have has a set of fields including email, password, firstname, lastname, etc. I created a page to edit the user profile and I'm able to successfully edit any field other than the password field. I tried creating a separate page just to change the password with its own forms, but even then, when I try to save the new password value nothing happens.
models.py
class User(models.Model):
First_Name = models.CharField(max_length=20)
Last_Name = models.CharField(max_length=20)
Password = models.CharField(max_length=20)
Email = models.EmailField(primary_key=True)
Address_Line1 = models.CharField(max_length=100)
Address_Line2 = models.CharField(max_length=100)
City = models.CharField(max_length=20)
State = models.CharField(max_length=2,validators=[State_validator])
ZIP_Code = models.IntegerField(validators=[Zip_Code_validator])
Country = models.CharField(max_length=100)
Phone_Number = models.CharField(max_length = 20,validators=[Numbers_validator])
Pickup_Arrangment = models.CharField(max_length=100)
Preferred_Contact = models.CharField(max_length=100)
def __str__(self):
return self.First_Name + self.Last_Name
forms.py
class PersonalManagementForm(forms.ModelForm):
class Meta:
model = models.users.User
fields = ['First_Name','Last_Name','Email','Password','Address_Line1','Address_Line2','City','State','ZIP_Code','Country','Phone_Number','Pickup_Arrangment', 'Preferred_Contact' ]
widgets = {
'First_Name': TextInput(attrs={'required': True}),
'Last_Name': TextInput(attrs={'required': True}),
'Email': TextInput(attrs={'required': True}),
'Password': PasswordInput(attrs={'required': True}),
'Address_Line1': TextInput(attrs={'required': True}),
'Address_Line2': TextInput(attrs={'required': False}),
'City': TextInput(attrs={'required': True}),
'State': TextInput(attrs={'required': True}),
'ZIP_Code': TextInput(attrs={'required': True}),
'Country': TextInput(attrs={'required': True}),
'Phone_Number': TextInput(attrs={'required': True}),
'Pickup_Arrangment': TextInput(attrs={'required': True}),
'Preferred_Contact': TextInput(attrs={'required': True})
}
def __init__(self, *args, **kwargs):
super(PersonalManagementForm, self).__init__(*args, **kwargs)
views.py
def personalmanagemnet(request):
myuser = is_logged_in(request)
if not myuser:
return HttpResponseRedirect("/login/")
personalmanagemnet_form = PersonalManagementForm(request.POST or None, instance=myuser)
if personalmanagemnet_form.is_valid():
personalmanagemnet_form.save()
return HttpResponseRedirect('/dashboard')
update_context = {
'update_form': personalmanagemnet_form,
}
return render(request, 'personalmanagemnet.html', update_context )
Almost all of the answers in stack overflow correspond to using the Django User model so it doesn't help in this case. How is it possible to update a password field manually in django?