Solution for How to implement extended auth-User model in SignUp form in Django?
is Given Below:
I want to add more fields in auth-User model. So, according to this docs(https://docs.djangoproject.com/en/3.2/topics/auth/customizing/#extending-the-existing-user-model) I created a ‘UserProfile’ model in one-to-one relation with auth-user. But it’s not working in forms.py. Actually, I couldn’t implement it in forms.py
Here is my code:
models.py
class UserProfile(models.Model):
user = models.OneToOneField(User, related_name="userprofile", on_delete=models.CASCADE)
profile_picture = models.ImageField()
forms.py
class CustomSignupForm(SignupForm):
profile_picture = forms.ImageField()
def signup(self, request, user):
up = user.userprofile
user.userprofile.profile_picture = self.cleaned_data['profile_picture']
up.profile_picture = self.cleaned_data['profile_picture']
user.save()
up.save()
return user
Even after SignUp I don’t get any object in ‘UserProfile’.