Created
December 17, 2010 03:49
-
-
Save rjregenold/744457 to your computer and use it in GitHub Desktop.
Django Edit Profile Form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EditUserForm(forms.ModelForm): | |
class Meta: | |
model = User | |
fields = ('first_name', 'last_name', 'email',) | |
class EditProfileForm(forms.ModelForm): | |
def __init__(self, *args, **kwargs): | |
super(EditProfileForm, self).__init__(*args, **kwargs) | |
profile = kwargs.get('instance') | |
if profile: | |
kwargs['instance'] = profile.user | |
self.user_form = EditUserForm(*args, **kwargs) | |
self.fields.update(self.user_form.fields) | |
self.initial.update(self.user_form.initial) | |
def save(self, *args, **kwargs): | |
self.user_form.save(*args, **kwargs) | |
return super(EditProfileForm, self).save(*args, **kwargs) | |
class Meta: | |
model = UserProfile | |
exclude = ('user',) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment