Skip to content

Instantly share code, notes, and snippets.

@rjregenold
Created December 17, 2010 03:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rjregenold/744457 to your computer and use it in GitHub Desktop.
Save rjregenold/744457 to your computer and use it in GitHub Desktop.
Django Edit Profile Form
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