UserProfileForm

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
class UserProfileForm(forms.ModelForm):
    first_name = forms.CharField(label=_(u'Prenom'), max_length=30)
    last_name = forms.CharField(label=_(u'Nom'), max_length=30)

    def __init__(self, *args, **kw):
        super(forms.ModelForm, self).__init__(*args, **kw)
        self.fields['first_name'].initial = self.instance.user.first_name
        self.fields['last_name'].initial = self.instance.user.last_name

        self.fields.keyOrder = [
            'first_name',
            'last_name',
            '...some_other...',
            ]

    def save(self, *args, **kw):
        super(forms.ModelForm, self).save(*args, **kw)
        self.instance.user.first_name = self.cleaned_data.get('first_name')
        self.instance.user.last_name = self.cleaned_data.get('last_name')
        self.instance.user.save()

    class Media:
        model = UserProfile

More like this

  1. notify admin what fields have changed in form submission by pjv 3 years, 4 months ago
  2. User Profile minimal code by Natim 2 years, 8 months ago
  3. filter dates to user profile's timezone by Scanner 7 years ago
  4. Simple profile middleware by limodou 7 years, 1 month ago
  5. mask_email filter by jkocherhans 7 years, 1 month ago

Comments

(Forgotten your password?)