title: Extending form.is_valid()
body: <p>I am learning Django, and i stumbled upon something that I need help with:</p>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class UserForm(forms.ModelForm):
      password1 = forms.CharField(widget=forms.PasswordInput())
      password2 = forms.CharField(widget=forms.PasswordInput())
  
      class Meta:
          model = User
          fields = ('username', 'email', 'password1','password2')
  
      def password_matched(self):
          if self.data['password1'] != self.data['password2']:
              self.errors['password'] = 'Passwords do not match'
              return False
          else:
              return True
  
      def is_valid(self):
          valid = super(UserForm,self).is_valid()
          password_matched = self.password_matched()
          if valid and password_matched:
              return True
          else:
              return False
  </code></pre>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>def register(request):
       #blah...
       user.set_password(user.password)
       # user.set_password(user.password1) doesn't work ! WHY!?
  </code></pre>
  
  <p>So basically, I am checking if <code>pw1 == pw2</code>,<br>
  after checking, I wish to set the user's password to password1.<br>
  I initially used the line <code>user.set_password(user.password1)</code> but it complained that User object doesn't have <code>password1</code>, yet it worked when I used <code>password</code>.</p>
  
  <p>Why is that? Thanks.</p>