Guest User

Untitled

a guest
Jul 17th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. class EditUserForm(forms.ModelForm):
  2. class Meta:
  3. model = User
  4. fields = ('first_name', 'last_name', 'email',)
  5.  
  6. class EditProfileForm(forms.ModelForm):
  7. def __init__(self, *args, **kwargs):
  8. super(EditProfileForm, self).__init__(*args, **kwargs)
  9.  
  10. profile = kwargs.get('instance')
  11. if profile:
  12. kwargs['instance'] = profile.user
  13.  
  14. self.user_form = EditUserForm(*args, **kwargs)
  15.  
  16. self.fields.update(self.user_form.fields)
  17. self.initial.update(self.user_form.initial)
  18.  
  19. def save(self, *args, **kwargs):
  20. self.user_form.save(*args, **kwargs)
  21. return super(EditProfileForm, self).save(*args, **kwargs)
  22.  
  23. class Meta:
  24. model = UserProfile
  25. exclude = ('user',)
Add Comment
Please, Sign In to add comment