2011-03-14 51 views
1
class UserField(forms.EmailField): 
def clean(self, value): 
    super(UserField, self).clean(value) 
    try: 
     User.objects.get(username=value) 
     raise forms.ValidationError("There is an existing account associated with this email.") 
    except User.DoesNotExist: 
     return value 

try除了方法很簡單。但是,我有一個很難搞清楚的瞭解django表單的問題

super(UserField, self).clean(value) 

回答

2

super(UserField, self).clean(value)是調用父類的方法:forms.EmailField.clean(value)檢查電子郵件很好地形成。